C语言实现链表

C语言实现链表

C语言实现链表 – c语言程序开发技术文章 – 红黑联盟

C代码 /* * @author: lizhenbin * @date: 2011-09-14 * @descrption: list operation */ #include <stdio.h> #include <stdlib.h> #include <conio.h> #define NULL 0 student {long num;student *next; };student *create() {student *p;struct student *q;long x;head = (struct student*)malloc(sizeof(struct student));q = head;head->next = NULL;printf();scanf(,&x);while(x!=0){p = (struct student*)malloc(sizeof(struct student));p->num = x;p->next = NULL;q->next = p;p->prior = q;q = p;scanf(,&x);}return head; }print(struct student *head) {struct student *p;p = head->next;printf();if(p==NULL){printf();}while(p!=NULL){printf(, p->num);p = p->next;}printf(); }del(struct student *head) {struct student *p;struct student *q;int i;int j=0;printf();scanf(, &i);if(i<1){printf(, i);printf();scanf(, &i);}p = head;while(j<=i-1 && p!=NULL){p = p->next;j++;}if(p==NULL){printf(, i);exit(1);}else{q = p;p->prior->next = p->next;p->next->prior = p->prior;p = p->next;free(q);} }insert(struct student *head) {struct student *p;struct student *q = head;int i;int j = 0;p = (struct student*)malloc(sizeof(struct student));printf();scanf(, &p->num);printf(,p->num);scanf(, &i);if(i<1){printf(, i);printf();scanf(, &i);}while(j<=i-1 && q->next!=NULL){q = q->next;j++;}if(q->next==NULL && j!=i){p->next = NULL;p->prior = q;q->next = p;}else{q->prior->next = p;p->prior = q->prior;p->next = q;q->prior = q;} }search(struct student *head) {struct student *p;long number, i=1, j=0;printf();scanf(, &number);p = head->next;printf();while(p!=NULL){if(p->num==number){printf(,i);j = 1;}p = p->next;i++;}if(j==0){printf(,number);} }student *filein() {struct student *p1;struct student *p2;struct student *head;int i = 0;FILE *fp;;printf(, file);))==NULL){printf(, file);exit(0);}p2 = (struct student*)malloc(sizeof(*p1));head = p2;p1 = (struct student*)malloc(sizeof(*p1));while(fread(p1, sizeof(*p1), 1, fp)==1){i++;p2->next = p1;p2 = p1;p1->next = NULL;p1 = (struct student*)malloc(sizeof(*p1));}free(p1);fclose(fp);if(i==0){printf(, file);}return head; }savefile(struct student* head) {struct student *p1;FILE *fp;;printf(, file);printf();))==NULL){printf(, file);exit(0);}p1 = head->next;while(p1!=NULL){fwrite(p1, sizeof(struct student), 1, fp);p1 = p1->next;}fclose(fp); } showMenu() {printf();printf();printf();printf();printf();printf();printf();printf();printf();printf();printf();printf(); } main() {int a=0;struct student *la;la = create();/*la = (struct student*)malloc(sizeof(struct student));la->next = NULL;*/while(1){showMenu();scanf(, &a);switch(a){case 1: insert(la); break;case 2: del(la); break;case 3: search(la); break;case 4: filein(); break;case 5: savefile(la); break;case 6: print(la); break;case 7: showMenu(); break;case 8: exit(1););break;}} }作者“萧萧易水寒”

posted on

,香港空间,美国空间,香港服务器生活会变成什么样子?正因为时光流逝一去不复返,

C语言实现链表

相关文章:

你感兴趣的文章:

标签云: