栈和队列的存储及基本操作

实验题目: 栈和队列的存储及基本操作

一、实验目的
1、掌握栈的顺序存储及链式存储实现,并实现进栈与出栈操作;
2、掌握队列的顺序存储及链式存储实现,并实现入队与出队操作。
二、实验作业

在给出部分代码的基础上完成:
1.在顺序栈存储体上,编写进栈与出栈函数,在主函数调用进栈与出栈,实现若干次的进栈与出栈操作。

2.在链栈存储体上,编写进栈与出栈函数,在主函数调用进栈与出栈,实现若干次的进栈与出栈操作。

3.在循环顺序队存储体上,编写入队与出队函数,在主函数调用入队与出队,实现若干次的入队与出队操作。

4.在链队存储体上,编写入队与出队函数,在主函数调用入队与出队,实现若干次的入队与出队操作
三、实验内容
1、

 Seqstack push(Seqstack L,int x)
{  if(L.top==MAXSIZE-1)
   printf("栈满\n");
  else
  {L.top++;
  L.data[L.top]=x;
  }
  return L;
 }

 Seqstack  pop(Seqstack L)
{  int x;
 if(L.top==-1)
   printf("栈空\n");
  else
  { x=L.data[L.top];
    L.top--;
 printf("%d\n",x);
  }
  return L;
 }

2、

 node* push(node* top,int x)
{  node*s;
   s=(node*)malloc(sizeof(node));
  s->data=x;
  s->next=top;
  top=s;
  return top;
 }

node*  pop(node* top)
{  int x;
   node*s;
 if(top==NULL)
   printf("栈空\n");
  else
  { s=top;
   x=top->data;
    top=top->next;
   free(s);
 printf("%d\n",x);
  }
  return top;
 }

3、

 Sequeue inqueque(Sequeue L,int x)
{  if((L.rear+1)%MAXSIZE==L.front)
   printf("对满\n");
  else
  { L.rear=(L.rear+1)%MAXSIZE;
	L.data[L.rear]=x;
  }
  return L;
 }

 Sequeue  outqueque(Sequeue L)
{  int x;
 if(L.front==L.rear)
   printf("对空\n");
  else
  { x=L.data[(L.front+1)%MAXSIZE];
    L.front=(L.front+1)%MAXSIZE;
   printf("%d\n",x);
  }
  return L;
 }

4、

linkqueue inqueque(linkqueue L,int x)
{  node*s;
   s=(node*)malloc(sizeof(node));
   s->data=x;
   L.rear->next=s;
   L.rear=s; 
  
  return L;
 }
 linkqueue  outqueque(linkqueue  L)
{  int x; node*s;
 if(L.front==L.rear)
   printf("对空\n");
  else
  {     s=L.front->next;
	  if(L.front->next==L.rear)
	  {x=s->data;
         printf("%d\n",x);
         L.rear=L.front;
		free (s);
	  }
	  else
	  {x=s->data;
         printf("%d\n",x);
	 L.front->next=s->next;
	free (s);
	  } 
  }
  return L;
 }

四、实验结果
(实验结果截图)
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

五、实验心得

我想静静♥

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半夏风情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值