C语言中关於栈的问题

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:56:42
请问在C语言里面,如何分别用数组和链表的方式做出栈里的pop和push的效果?
同样,在C里面如何分别用数组和链表的方式表达出queues里面的dequeue和enqueue?
万分感谢

还是给实例吧,程序很容易理解的,就不加注释了。
程序均在dev-c++或vs2005下编译通过。

一 数组模拟栈
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define MaxSize 256

int stack[MaxSize];
int top=-1;

void push(int value)
{
int i;
if(top>=MaxSize)
printf("\nThe stack is full!\n");
else
{
printf("\nThe stack content before push(top->bottom):");
for(i=top;i>=0;i--)
printf("[%d]",stack[i]);
top++;
stack[top]=value;
printf("\nThe stack content after push(top->bottom):");
for(i=top;i>=0;i--)
printf("[%d]",stack[i]);
printf("\n");
}
}

int pop()
{
int temp;
int i;
if(top<0)