C/C++ 知识回顾 栈的入栈与出栈
2017-03-06 22:17
316 查看
#include<iostream> using namespace std; typedef struct student { int data; struct student * next; }node; typedef struct stackqueque { node * top, *zhandi; } Stack; Stack * push(Stack * stack,int num) { node *s = (node *)malloc(sizeof(node)); s->data = num; s->next = NULL; if (stack->top==NULL) { stack->top = s; stack->zhandi = s; } else { stack->top->next = s; stack->top = s; } return stack; } int pop(Stack *stack) { if (stack->top==NULL) { cout << "栈为空" << endl; return -1; } if (stack->top==stack->zhandi) { int x = stack->top->data; stack->top = NULL; stack->zhandi = NULL; return x; } else { node* p = stack->zhandi; while (p->next!=stack->top) { p = p->next; } node *q = stack->top; int x = stack->top->data; p->next = NULL; stack->top = p; free(q); return x; } } int main() { }
相关文章推荐
- C++ 基础知识回顾
- C++回顾(一)——基本知识
- C++ Prime 简单回顾-基础知识
- C++知识回顾之__stdcall、__cdcel和__fastcall三者的区别
- 数据结构之栈的初始化、创建、入栈、出栈、销毁-c++代码实现及运行实例结果
- 数据结构之栈的初始化、创建、入栈、出栈、销毁-c++代码实现及运行实例结果
- C++ 知识回顾总结 -- 指针
- C++ 知识回顾总结 -- queue 队列容器
- 以cocos2d-x之名:c++知识回顾一
- C++基础知识回顾
- 数据结构之栈的初始化、创建、入栈、出栈、销毁-c++代码实现及运行实例结果
- 数据结构之栈的初始化、创建、入栈、出栈、销毁-c++代码实现及运行实例结果
- CPP.Freshman Vol.1 C++基础知识回顾
- C++友元知识回顾
- C++重点知识回顾
- 数据结构之栈的初始化、创建、入栈、出栈、销毁-c++代码实现及运行实例结果
- C/C++ 知识回顾 内存分配的类别、堆和栈的区别
- C/C++知识回顾 容器
- C++基础知识总结与回顾--5.5共享数据的保护
- c++ 采用链式结构实现关于入栈,出栈,打印栈的操作