#include<stdio.h>
#include<malloc.h>
typedef struct list{
int data;
struct list *next;
}LIST;
void InitList(LIST **p){ /*初始化链表*/
*p=NULL;
}
void InsertList1(LIST **p,int item,int rc){
int i;
LIST *u ,*q,*r;
u=(LIST *)malloc(sizeof(LIST));
u->data=item;
for(i=0,r=*p;i<rc&&r!=NULL;i++){
q=r;
r=r->next;
}
if(r==*p){
*p=u;
}else{
q->next=u;
}
u->next=r;
}
void InsertList2(LIST **p,int item){
/*向有序链表[p]插入键值为[item]的节点*/
LIST *u, *q,*r;
u=(LIST *)malloc(sizeof(LIST));
u->data=item;
for(r=*p;r!=NULL && r->data<item;q=r,r=r->next);
if(r==*p){
*p=u;
}else{
q->next=u;
}
u->next=r;
}
/*删除键值为[item]的链表节点,返回0:删除成功 1:没找到*/
int DeleteList(LIST **p,int item){
LIST *q,*r;
q=*p;
if(q==NULL){
return 1;
}
if(q->data==item){
*p&
线性表-链表实现增删改查
最新推荐文章于 2022-04-25 22:13:39 发布
本文展示了如何使用C语言实现链表的初始化、指定位置插入、有序插入、查找、删除和输出等基本操作。包括InsertList1、InsertList2、DeleteList、FindList等函数的详细代码。
摘要由CSDN通过智能技术生成