教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 高等教育 >

《数据结构》实验指导书 - 图文(4)

来源:网络收集 时间:2026-01-24
导读: node *Createlist() { node *p1,*p2,*head; int i,n,m; head=(node*)malloc(sizeof(node)); head->next = NULL; printf(\ scanf(\ p1 = head; for(i=1;i p2 = (node*)malloc(sizeof(node)); p1->next = p2; printf(

node *Createlist() {

node *p1,*p2,*head; int i,n,m;

head=(node*)malloc(sizeof(node)); head->next = NULL;

printf(\ scanf(\ p1 = head;

for(i=1;i<=n;i++) {

p2 = (node*)malloc(sizeof(node)); p1->next = p2;

printf(\ scanf(\ p2->next=NULL; p1 = p2; }

print_hlink_list(head); return head; }

int main() {

node *head,*k; int x,y,z;

head = Createlist();

printf(\ scanf(\

printf(\ scanf(\

insert_x_after_y(head,y,x); print_hlink_list(head);

printf(\ scanf(\ delete_z(head,z);

print_hlink_list(head); getch(); }

实验四 顺序栈的基本操作

一、

实验目的:

1. 握栈的基本概念;

2. 掌握顺序栈的建立、入栈和出栈等方法; 3. 了解链栈、链队的概念及有关操作。

二、 实验内容:

1. 完成栈的基本操作;

三、 实验要求:

1. 认真阅读、掌握和上机运行本实验的程序; 2. 记录程序的运行结果,并结合程序进行分析; 3. 对程序的核心功能代码进行注释。

四、 五、

实验学时:2学时 实验步骤:

1. 实验准备:

(1)针对第二章课后编程项目的第1-4题,完成编程; (2)阅读实验步骤中的函数,写出函数功能;

2. 拓展练习:阅读下列程序,写出各子函数功能和程序运行结果,再上机调试运行。 (1)栈的基本运算

#include \

int push(int stack[],int maxn,int toppt,int x) /*栈空间最多能存maxn个结点*/ {

if(toppt>=maxn) {

printf(\ return 1; }

stack[toppt]=x; ++toppt; return 0; }

int pop(int stack[],int toppt,int cp) {

if(toppt==0) {

printf(\ return 1; }

--toppt;

cp=stack[toppt]; return 0;

}

void main() {

int a[10],top,m,j,x,flag;

printf(\ scanf(\

printf(\ for(j=0;j

printf(\ for(j=0;j

printf(\ scanf(\

flag=push(a,10,top,x); if(flag==0) {

printf(\ for(j=0;j

flag=pop(a,top,x); if(flag==0) {

printf(\

printf(\ for(j=0;j

getch(); }

(2)十进制转换二进制

#define Stack_Size 255 typedef struct

{int elem[Stack_Size]; int top; }SeqStack;

int push(SeqStack *S, int x){

if(S->top==Stack_Size-1) return(0); S->top++;

S->elem[S->top]=x; return(1); }

int pop(SeqStack *S, int *x) {

if(S->top==-1)

{ printf(\ else {

*x=S->elem[S->top]; S->top--;

return(1); } }

《数据结构》实验指导书 - 图文(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/608417.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)