📄 dan lian biao.txt
字号:
单链表的建立,插入,删除源程序:
#include "stdio.h"
#include "alloc.h"
#define null 0
#define LEN sizeof(struct Node)
typedef struct Node
{ char data;
struct Node *next;
}Lnode,*Linklist;
listinsert(Linklist L,int i,char x)
{ Linklist p,s;
int j;
p=L;j=0;
while(p!=null&&j<i-1)
{ p=p->next;
j++;
}
s=(Lnode *)malloc(LEN);
s->data=x;
s->next=p->next;
p->next=s;
}
listdelete(Linklist L,int i)
{ Linklist p,s;
int j;
p=L;j=0;
while(p->next!=null&&j<i-1)
{ p=p->next;
++j;
}
if(j!=i-1)
{ printf("error!");
}
s=p->next;
p->next=s->next;
}
print(Linklist head,int n)
{ Linklist p;int i;
p=head;
printf("the data of the list are:\n");
for(i=0;i<=n+1;i++)
{ printf("%c",p->data);
p=p->next;
}
}
main()
{ Lnode *head,*p,*q;
char x;
int i,n;
printf("your number:");
scanf("%d",&n);
head->next=null;
q=head;
for(i=0;i<=n;i++)
{p=(Lnode *)malloc(LEN);
scanf("%c",&p->data);
q->next=null;
q->next=p;
q=p;
}
print(head,n);
while(head!=null)
{ printf("\nPlease input the insert point i=");
scanf("%d",&i);
if(i<1||i>n)
{ printf("The insert point has not been found!\n");
break;
}
else
{ printf("Please input the insert data:");
scanf("%c\n",&x);
x=getchar();
getchar();
printf("Found!\n");
listinsert(head,i,x);
print(head,n+1);
}
}
while(head!=null)
{ printf("\nPlease input the delete point i=");
scanf("%d",&i);
if(i<1||i>n)
{ pirntf("The delete point has not been found!\n");
break;
}
else
{ printf("Found!\n");
listdelete(head,i);
print(head,n);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -