//线性表的基本操作
#include <iostream.h>
#include<stdio.h>
#include <stdlib.h>
#define Qelemtype char
#define sqlist L
typedef struct Qnode
{
Qelemtype data;
Qnode *next;
} sqlist;
void initlist (sqlist L)
{ //sqlist L;
L=(Qnode )malloc(sizeof(Qnode));
L->next=NULL;
}
void createlist(sqlist &L,int n)
{
int i;
initlist(&L);
struct Qnode p;
for(i=n;i>0;i--)
{
p=(sqlist)malloc(sizeof(Qnode));
scanf("&p->data=%c",p->data);
p->next=l->next;
L->next=p;
}
}
char listinsert(sqlist &L,int i,Qelemtype e)
{int j;
struct Qnode p;
p=L;
j=0;
while (p->next!=NULL&&j<i-1)
{p=p->next;
j++;
}
if(!p&&j>i-1)
return -1;
else s= (sqlist)malloc(sizeof(Qnode));
s-data=e;
s->next=p->next;
p->next=s;
return ok;
}
}
void listdelete(sqlist L,int i,Qelemtype e)
{p=L;
int j=0;
while(p->next!=null&&j<i-1)
{
p=p->next;
j++;
}
if(!p||j>i-1) return -1;
q=p->next;
p->next=q->next;
e=q->data;
return q->data;
free(q);
}
void display(Sqlist *L,char * commemt)
{sqlist *p;
p=L->next;
printf("输出结果如下\n");
while(p)
{
printf("p->data=",p->data);
p=p->next;
}
}
void main()
{
sqlist L;
char e;
int i=0;
initlist L;
create(&L,i,e);
display(L,"the result");
listinseeeert(&L,6,c);
display(L,"the result");
listdelete(&L,7);
display(L,"the result");
}
----------------解决方案--------------------------------------------------------
好
----------------解决方案--------------------------------------------------------