1、
#include
2、 r=s; } r->next = NULL; } void DispList(LinkList h) { LinkList r = h->next; while(r != NULL) { printf("%d ",r->data); r = r->next; } putchar('\n'); } void InsertList(LinkList h, int x, int y) { LinkList s, p, q; s = new Lnode; s->data = y; q = h; p =
3、q->next; while((p!=NULL) && (p->data != x)) { q = p; p = p->next; } s->next = p; q->next = s; } void DeleteList(LinkList h, int x) { LinkList p, q; q = h; p = q->next; while((p != NULL) && (p->data != x)) { q = p; p = p->next; } if(p == NULL) printf("no");
4、 else { q->next = p->next; delete(p); printf("yes"); } } void Countnode(LinkList h, int &j) { LinkList r; r = h->next; while(r != NULL) {j++; r = r->next; } } int main() { int i, a[100]={0}, x, y, n, j=0; char p; LinkList h; h = new Lnode; h->next = NU
5、LL; printf("主菜单\n"); printf("1.创建单链表\n"); printf("2.结点的插入\n"); printf("3.结点的删除\n"); printf("4.统计结点个数\n"); printf("5.退出系统\n"); printf("输入单链表的元素个数是n, n<=100 \n"); scanf("%d",&n); printf("请输入元素:\n"); for(i = 0; i < n; i++) { scanf("%d",&a[i]); } do {
6、 printf("请输入选择p(1-5)\n"); scanf(" %c",&p); switch(p) { case '1': CreatList(h, a, n); DispList(h);break; case '2': printf("在x的结点之前插入值y的结点,请输入x, y\n"); scanf("%d%d",&x,&y); InsertList(h, x, y); DispList(h);break; case '3': printf("删除值为x的结点
7、请输入x\n"); scanf("%d",&x); DeleteList(h, x); DispList(h);break; case '4': printf("统计结点个数\n"); Countnode(h,j); printf("结点个数为%d\n",j);break; case '5': printf("退出系统\n"); break; default:printf("选择错误! 请重新选择p(1-5)\n") ;p='0'; } }while(p < '5'
8、);
return 0;
}
#include
9、
10、 return 0;
m=l->data[i-1];
return 1;
}
int LocateElem(SqList *l,int k)
{int i=0;
while((i
11、j,e,k,v, xx=0;
char a[100], b[100], c[100];
InitList(A);
InitList(B);
cout<<"how many elements in A?"< 12、for(i=0;i 13、ta[j])break;
}
if(j==k)
cout<<(c[xx++]=A->data[i])<<' ';
}
cout< 14、B |_| B - A:"< 15、>next = NULL;
s->data = 0;
}
int EmptyStack( ListStack *s)
{
return(s->next== NULL);
}
void Push(ListStack *s,int e)
{
ListStack *p = new ListStack;
p->data = e;
p->next = s->next;
s->next = p;
}
void GetTop(ListStack *s,int &e)
{
if (EmptyStack(s))
cout 16、<<"栈空!"< 17、 cout<<"Stack is empty!"< 18、
for(i=0;i 19、uct sqstack
{char data[MaxSize];
int top;
}SqStack;
void InitStack(SqStack *&s)
{
s=new SqStack;
s->top=-1;
}
int EmptyStack( SqStack *s)
{
return(s->top== -1);
}
int FullStack(SqStack *s)
{
return(s->top== MaxSize-1);
}
void Push(SqStack *s,char e)
{ if (Ful 20、lStack(s)) return ;
s->top++;
s->data[s->top]=e;
return ;
}
void GetTop(SqStack *s,char &e)
{ if (EmptyStack(s))
return ;
e=s->data[s->top];
return ;
}
char Pop(SqStack *s)
{ char e;
if (EmptyStack(s))
return 0;
e=s->data[ s->top];
s->t 21、op--;
return e;
}
void DispStack(SqStack *s)
{int i;
if(EmptyStack(s))
cout<<"Stack is empty!"<






