在公司,读了很久文档,很累,休息下,写了个链表,算是弥补以前 。。。 LinkList.h文件: #include <stdio.h> struct LinkList { int value; struct LinkList *next; }; typedef struct LinkList *pNode; typedef struct LinkList Node; void CreateList(pNode head) { pNode p = head; int nodeValue; while ( true ) { printf("input the node value:"); scanf("%d",&nodeValue); if ( 0 != nodeValue ) { pNode tempNode = (pNode)malloc(sizeof(Node)*1); tempNode->value = nodeValue; tempNode->next = NULL; p->next = tempNode; p = p->next; } else break; } } //在指定的pos节点前添加node void AddNode(pNode head,pNode node,int pos) { pNode p = head; pNode pre; int iIndex = 0; while (iIndex < pos && p && p->next) { pre = p; p = p->next; iIndex++; } if (p) { pre->next = node; node->next = p; } } //删除指定的节点 void DelNode(pNode head,Node node) { } void exchange(int& a,int& b) { int temp = a; a = b; b = temp; } void SortingList(pNode head) { pNode pre = head->next; pNode cur; while(pre) { cur = pre->next; while (cur) { if (pre->value > cur->value) { exchange((pre->value),(cur->value)); } cur = cur->next; } pre = pre->next; } } main函数文件主要代码: pNode head = (pNode)malloc(sizeof(Node)*1); head->value = 0; head->next = NULL; CreateList(head); pNode p = head; while (p&&p->next) { p = p->next; printf("%d ",p->value); } Node node; node.value = 10; node.next = NULL; AddNode(head,&node,3); printf("after added the node:"); p = head; while (p&&p->next) { p = p->next; printf("%d ",p->value); } SortingList(head); printf("after sorting:"); p = head; while (p&&p->next) { p = p->next; printf("%d ",p->value); } getchar(); getchar(); 写了小会儿,没意思,算了,回到工作上 。。。