大一c语言实训课题,达人解决个大一的实训课题

一个简单的线性表

#include”stdio.h”

typedef struct linknode

{char data;

struct linknode *next;

}node;

node *head;

int n=0;

void CreateList()

{

node *p,*s;

char x;

int z=1;

head=new node;

p=head;

printf(“\n\t\t createlist”);

printf(“\n\t\t please input word,end’x'!\n”);

while(z)

{

printf(“\t\t input:”);

scanf(“%c”,&x);

getchar();

if(x!=’x')

{

s=new node;

n++;

s->data=x;

p->next=s;

s->next=NULL;

p=s;

}

else z=0;

}

}

void InsList(int i,char x)

{

node *s,*p;

int j;

s=new node;

n++;

s->data=x;

if(i==0)

{

s->next=head;

head=s;

}

else

{

p=head;j=1;

while(p!=NULL&&j

{

j++;

p=p->next;

}

if(p!=NULL)

{

s->next=p->next;

p->next=s;

}

else

printf(“\t\t no find!\n”);

}

}

void DelList(char x)

{

node *p,*q;

if(head==NULL)

{

printf(“\t\t lianbiaoxiayi!\n”);

return;

}

if(head->next==NULL)

{ printf(“\t\t linklist kong!”);

return;

}

q=head;

p=head->next;

while(p!=NULL&&p->data!=x)

{   q=p;

p=p->next;

}

if(p!=NULL)

{q->next=p->next;

delete p;

n–;

printf(“\t\t %c already DEL!”,x);

}

else

printf(“\t\t no find!\n”);

}

void ShowList()

{ node *p=head;

printf(“\n\t\t showlist:”);

if(head->next==NULL||p==NULL)

printf(“\n\t\t kong list!\n”);

else

{

printf(“\n\t\t”);

while(p->next!=NULL)

{printf(“%5c”,p->next->data);

p=p->next;

}

}

}

void main()

{   head=NULL;

int choise,i,j=1;

char x;

while(j)

{printf(“\n\n\n\n”);

printf(“\t\t\t   linklist’s son\n”);

printf(“\n\t\t*********************”);

printf(“\n\t\t*   1—createlist  *”);

printf(“\n\t\t*   2—inslist     *”);

printf(“\n\t\t*   3—dellist     *”);

printf(“\n\t\t*   4—showlist    *”);

printf(“\n\t\t*   0—quit        *”);

printf(“\n\t\t*********************”);

printf(“\n\t\t plsase chose(0—4):”);

scanf(“%d”,&choise);getchar();

if(choise==1)

CreateList();

else if (choise==2)

{   printf(“\n\t\t please input i and x:”);  /*输入格式 例:“4,X”插入4*/

scanf(“%d,%c”,&i,&x);

InsList(i,x);

}

else if (choise==3)

{   printf(“\n\t\t please input del NO:”);

scanf(“%c”,&x);

DelList(x);

}

else if (choise==4)

if(head==NULL)

printf(“\n\t\t please createlist!”);

else

ShowList();

else if (choise==0)

j=0;

else

printf(“\n\t\t Wrong!!!\n”);

}

}

插入时程序不对,输入“4,x”时,显示的是“x”

有点迷茫。。。

是个子程序

主程序:

#include”stdio.h”

void Linklist()

{

}

void main(void)

{

int choice;

char ch;

ch=’y';

while(ch==’y')

{

printf(“\n\n\n\n\t\t  system  \n\n\n”);

printf(“\t\t    list    “);

printf(“\n\t\t******************”);

printf(“\n\t\t   1—linklist***”);

printf(“\n\t\t   2—stack   ***”);

printf(“\n\t\t   3—queue   ***”);

printf(“\n\t\t   4—string  ***”);

printf(“\n\t\t   5—btree   ***”);

printf(“\n\t\t   6—graph   ***”);

printf(“\n\t\t   7—search  ***”);

printf(“\n\t\t   8—sort    ***”);

printf(“\n\t\t   0—quit    ***”);

printf(“\n\t\t******************”);

printf(“\n\n\t\t  chose(0—8):”);

scanf(“%d”,&choice);

getchar();

switch(choice)

{

case 1:Linklist();break;

case 2:break;

case 3:break;

case 4:break;

case 5:break;

case 6:break;

case 7:break;

case 8:break;

case 0:ch=’n';break;

default: printf(“wrong”);

}

}

}

怎样能让2个连在一起运行?

怎样在程序中加“2链表合并”???

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值