#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
char data;
struct Node *next;
}Node,*LinkList;
void InitList(LinkList *H)
{
*H=(Node *)malloc(sizeof(Node));
(*H)->next=NULL;
}
void Create(LinkList H)
{
Node *s,*r;
char c;
int flag=1;
r=H;
while(flag)
{
c=getchar();
if(c!='$')
{
s=(Node*)malloc(sizeof(Node));
s->data=c;
r->next=s;
r=s;
}
else
{
flag=0;
r->next=NULL;
}
}
}
void OutList(LinkList H)
{
Node*p;
p=H->next;
while(p!=NULL)
{
printf("%c\t",p->data);
p=p->next;
}
}
int InsList(LinkList H,int i,char e)
{
Node *pre,*s;
int k;
pre=H;k=0;
while(pre!=NULL&&k<i-1)
{
pre=pre->next;
k=k+1;
}
if(k!=i-1)
{
printf("not appropriate");
return 0;
}
s=(Node*)malloc(sizeof(Node));
s->data=e;
s->next=pre->next;
pre->next=s;
return 1;
}
int DelList(LinkList H,int i,char* e)
{
Node *p,*r;
int k;
e=(char*)malloc(sizeof(char));
p=H;k=0;
while(p->next!=NULL&&k<i-1)
{
p=p->next;
k=k+1;
}
if(k!=i-1)
{
printf("not fit");
return 0;
}
r=p->next;
p->next=r->next;
*e=r->data;
free(r);
return 1;
}
int main()
{
Node *H; char e;
InitList(&H);
Create(H);
printf("Now show you the List\n");
OutList(H);
InsList(H,4,'e');
printf("\nThe list after Insert\n");
OutList(H);
DelList(H,3,&e);
printf("\nThe list after Del\n");
OutList(H);
return 0;
}