📄 stack.h
字号:
#ifndef STACK_H_INCLUDED
#define STACK_H_INCLUDED
int new_stack(pstack *head, int size)
{
(*head) = (pstack)malloc(sizeof(stack));
if ((*head) == NULL)
return -1;
(*head)->buf = (int *)malloc(sizeof(int)*size);
if ((*head)->buf == NULL)
return -1;
(*head)->buf_size = size;
(*head)->ptr = 0;
return 0;
}
int push(pstack head, int element)
{
if (head->ptr == head->buf_size - 1)
return -1;
head->ptr++;
head->buf[head->ptr] = element;
return 0;
}
int top(pstack head)
{
return head->buf[head->ptr];
}
int empty(pstack head)
{
if (head->ptr == 0)
return 1;
return 0;
}
int pop(pstack head)
{
if (empty(head))
return -1;
head->ptr--;
return 0;
}
void delete_stack(pstack *head)
{
free((*head)->buf);
free((*head));
}
#endif // STACK_H_INCLUDED
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -