69,369
社区成员
发帖
与我相关
我的任务
分享
struct node {
int capacity;
int top; /* 栈顶 */
int *array; /* 指向存储栈元素的数组 */
};
int
pop(struct node *S)
{
if (is_empty(S) == 1) { //表示栈空
//error
} else {
return S->array[S->top--];
}
}
fprintf(.....);
exit(-1);
return ERROR_NUM;
if (is_empty(S) == 0) {
i = pop(S);
}
int
pop(struct node *S)
{
assert(S != NULL);
assert(is_empty(S) == 0);
return S->array[S->top--];
}
if ((i = pop(S)) != ERROR_NUM) {
//正确取值
} else {
//错误处理
}
#include <stdio.h>
/** 栈的大小 **/
#define _MAX_ 10
/** 栈结构 **/
int array[_MAX_];
/** 栈指针 **/
int top = -1;
/** 是否为空栈 **/
int isEmpty()
{
return top == -1;
}
/** 栈是否满 **/
int isFull()
{
return top == _MAX_;
}
/** 数据入栈 **/
void push(int j)
{
if(!isFull())
array[++top] = j;
}
/** 数据出栈 **/
int pop()
{
if(!isEmpty())
return array[top--];
}
/** 当前栈指针位置的数据 **/
int peek()
{
return array[top];
}
int main()
{
push(20);
push(40);
push(60);
push(80);
while(isEmpty() != 1)
{
printf("%d,", pop());
}
}
/** 数据入栈 **/
void push(int j)
{
if(!isFull())
array[++top] = j;
}
/** 数据出栈 **/
int pop()
{
if(!isEmpty)
return array[top--];
}
#include <stdio.h>
/** 栈的大小 **/
int max = 10;
/** 栈结构 **/
int array[max];
/** 栈指针 **/
int top = -1;
/** 数据入栈 **/
void push(int j)
{
array[++top] = j;
}
/** 数据出栈 **/
int pop()
{
return array[top--];
}
/** 当前栈指针位置的数据 **/
int peek()
{
return array[top];
}
/** 是否为空栈 **/
int isEmpty()
{
return top == -1;
}
/** 栈是否满 **/
int isFull()
{
reutrn top == max
}
int main()
{
push(20);
push(40);
push(60);
push(80);
while(isEmpty() != 1)
{
printf("%d,", pop());
}
}