好文档 - 专业文书写作范文服务资料分享网站

(最新版)算法与数据结构实验报告

天下 分享 时间: 加入收藏 我要投稿 点赞

linklist *head,*s,*r,*p,*q,*m,*n; clrscr();

head=malloc(sizeof(linklist)); r=head;

printf(\ scanf(\ while(x!=0){

s=malloc(sizeof(linklist)); s->data=x; r->next=s; r=s;

scanf(\ }

r->next=NULL;

printf(\ scanf(\ p=head->next; while(p!=NULL){

if (p->datanext; else break; }

q=malloc(sizeof(linklist)); q->data=y; m=head;

while(m->next!=p) m=m->next; q->next=p; m->next=q; n=head->next;

printf(\

while(n!=NULL){

printf(\ n=n->next; } }

3、#include \#include \typedef struct node{ int data;

struct node *next; }linklist; main(){ int a;

linklist *head,*s,*r,*p,*q,*t; clrscr();

head=malloc(sizeof(linklist)); r=head;

printf(\ scanf(\ while(a!=0){

s=malloc(sizeof(linklist)); s->data=a; r->next=s; r=s;

scanf(\ }

r->next=NULL;

printf(\ p=head->next;

while(p){

printf(\ p=p->next; }

p=head->next; q=p->next; while(q!=NULL){ t=q->next; q->next=p; p=q; q=t; }

head->next->next=NULL; head->next=p;

printf(\ p=head->next; while(p!=NULL){

printf(\ p=p->next; } }

四、实验结果与分析(程序运行结果及其分析)

1、输入:1 2 3 a b c $ 输出结果:1 2 3 a b c

2、输入:input the order numbers : 1 3 5 7 8 9 0

Please input the insert value::4

输出结果:the list are: 1 3 4 5 7 8 9 3、输入:Input some numbers:1 3 4 5 8 0 输出结果:The linklist before changed is:

13458

After changed:

85431

五、实验体会(遇到问题及解决办法,编程后的心得体会)

遇到问题:编写成功后运行时,没有加入$导致程序运行不成功,不能够退出。后注意到这个问题才继续运行下去。

实验体会:在编写程序时,设置了结束字符一定要牢牢记住,并且在输入时观察仔细类型是什么,以及是否是输入一串有顺序的数字,编写成功不难,但是要规范格式,不能仅仅以完成程序为目的。而完成这一章的实验也让我了解了,顺序表便于查找不便于插入删除,而链表恰恰相反,链表的插入删除只需要移动指针,而顺序表要从后往前依次移动,二者各有优劣。

实验项目名称: 堆栈和队列 实验学时: 2 同组学生姓名: 实验地点: 工科楼A205 实验日期: 2013年10月30日 实验成绩: 批改教师: 批改时间:

(最新版)算法与数据结构实验报告

linklist*head,*s,*r,*p,*q,*m,*n;clrscr();head=malloc(sizeof(linklist));r=head;printf(\scanf(\while(x!=0){s=malloc(sizeof(linklist));s->data
推荐度:
点击下载文档文档为doc格式
28mog8msdk5o77k30e8m0fvqu4yw2700pbh
领取福利

微信扫码领取福利

微信扫码分享