123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869#include #include typedef struct node { int data; int counter; struct node *next;}*LIST,*pNode; LIST InitList() { pNode head; head = (pNode)malloc(sizeof(struct node)); head->data = 0; head->next = NULL; return head;} void Insert(LIST head,int x) { pNode newnode,p = head; if(p->next == NULL) { p->next = (pNode)malloc(sizeof(struct node)); p->next->data = x; p->next->counter = 1; p->next->next = NULL; return; } while(p->next) { if(p->next->data == x) { p->next->counter; return; } if(p->next->data > x) { newnode = (pNode)malloc(sizeof(struct node)); newnode->data = x; newnode->counter = 1; newnode->next = p->next; p->next = newnode; return; } p = p->next; } p->next = (pNode)malloc(sizeof(struct node)); p->next->data = x; p->next->counter = 1; p->next->next = NULL;} void Show(LIST head) { pNode p = head->next; while(p) { printf("] : %-d
",p->data,p->counter); p = p->next; }} int main() { int num; LIST head = InitList(); FILE *fin = fopen("data。
txt","rt"); if(fin == NULL) { printf("不能打开数据文件。
"); return 1; } while(fscanf(fin,"%d",&num) == 1) Insert(head,num); fclose(fin); Show(head); return 0;}。
全部