• 大小: 5KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-22
  • 语言: C/C++
  • 标签: C/C++  DoubleLinked  

资源简介

用C语言实现双向列表的创建,删除,添加节点,删除节点,插入节点,遍历节点,打印节点,并结合插入排序法实现了基于双向链表的升序排序。

资源截图

代码片段和文件信息

#include “List.h“

//file option port
void InsertSortlinked(char *inputfile char *outputfile)
{
FILE *in;
FILE *out; 
int data[100];
int ii = 0;
List myList = newList();

if ((in = fopen(inputfile “r“)) == NULL) /* open file TEST.txt */
{
fprintf(stderr “Cannot open output file.\n“);
return ;
}

if ((out = fopen(outputfile “w“)) == NULL) /* open file TEST.txt */
{
fprintf(stderr “Cannot open output file.\n“);
return ;
}

while (!(feof(in)))
{
fscanf(in “%d“ &data[ii]);
append(myListdata[ii]);
ii++;
}

InsertSort(myList);
printfList(myList);
printList(out myList);
freeList(myList);
fclose(in);
fclose(out);
}

//Insert Sort of Double-link List 
void InsertSort(List L)
{
Node n1n2tmppos;
int i;

n1 = getFront(L);
n2 = getNextNode(n1);

for (i=1; isize; ++i)
{
pos = NULL;
tmp = n2;
//compare
  while(n1 && (n1->data > tmp->data))
{

pos = n1;
n1 = getPrevNode(n1);
}

//iter
n2 = getNextNode(n2);

//insert and delete
if (pos != NULL)
{
insertBefore(L pos tmp->data);
detachNode(L tmp);
}
//iter
n1 = getPrevNode(n2);
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         25  2019-02-26 15:13  linux\in.txt

     文件       1140  2019-02-26 15:13  linux\InsertSortlinked.c

     文件       5009  2019-02-26 15:13  linux\List.c

     文件       5012  2019-02-26 15:13  linux\List.h

     文件       1380  2019-02-26 15:13  linux\ListClient.c

     文件        346  2019-02-25 19:39  linux\Makefile

     文件         26  2019-02-26 19:40  linux\out.txt

    ..AD...         0  2019-02-26 19:43  linux

----------- ---------  ---------- -----  ----

                12938                    8


评论

共有 条评论