c 鍊錶的增刪改查的操作

2022-08-30 13:45:14 字數 1909 閱讀 7827

#include#include#define len sizeof(struct student)

struct student;

//建立乙個鍊錶

struct student * create(void)else

p1 = (struct student *)malloc(len);

scanf("%d%lf",&(p1->num),&(p1->score));

p2->next = p1; }

p2->next = null;

return head;

}struct student *delw(struct student *start,int num)

p1 = start;

p2 = null;

//鍊錶不為空

//鍊錶只有乙個元素,且即為所要找的元素

/*if(p1->next==null&&p1->num == num)*/

while(p1->next!=null&&p1->num!=num)

if(num == p1->num)else

}else

return start;

}struct student *del(struct student *head,long num)

//鍊錶不為空

p1 = head;

while(p1->next!=null&&num!=p1->num)

if(num == p1->num)else

}else

printf("%ld not been found!\n",num);

return head;

}//刪除乙個節點

struct student * deletenode(struct student *start,int num)

p1 = p2 = start;

//只有乙個節點

if(start->next==null)

} //鍊錶不為空(兩個以上的節點)

//1:鍊錶的第乙個即為所要找的

if((start->num == num)&&(start->next!=null))

while(p1!=null)

p2 = p1;

p1 = p1->next;

} before->next = after;

return start;

}struct student * insert(struct student *head,struct student *stu)else

if(p1->num>p0->num)else

}else

return head; }

}void printlink(struct student *p)

}int main(void);

//建立乙個鍊錶

printf("建立乙個鍊錶:\n");

p_std = create();

printf("建立的鍊錶如下:\n");

printlink(p_std);

//插入乙個節點

printf("插入乙個節點:44\n");

p = &newstd;

p_afterinsert = insert(p_std,p);

printf("插入乙個節點後的列表如下:\n");

printlink(p_afterinsert);

//刪除乙個節點

printf("刪除乙個節點:44\n");

p_afterdel = deletenode(p_afterinsert,44);

printf("刪除乙個節點後的列表如下:\n");

printlink(p_afterdel);

system("pause");

}

mysql增刪改查鍊錶 鍊錶的增刪改查

include include 先定義鍊錶裡面的元素。typedef struct nodemynode 定義整個鍊錶。typedef struct linkmylink int isempty to mylink mylink mylink 判斷鍊錶是否為空。int push to mylinki...

C 鍊錶,增刪改查

main.c homework linklist created by jiumiao on 15 7 23.年 include include typedef struct npcnpc typedef struct nodenode node head null 定義乙個頭節點 新增節點 voi...

雙向鍊錶的增刪改查操作

阿濤,你要認真對待每一件事,你要瀟灑,你要做自己!前面複習了單向鍊錶和迴圈鍊錶的操作,寫得比較亂,現在寫個比較規整的雙向鍊錶的的各項操作。先上個截圖 全部 如下 include include define len sizeof struct doublelinklist typedef struc...