用单链表实现栈 Linked List implementation of stacks
2014-03-13 23:01
579 查看
struct Node { int data; Node* next; }; Node* top = NULL; void Push(int x) { Node* tmp = (Node*)malloc(sizeof(Node)); tmp->data = x; tmp->next = top; top = tmp; } void Pop() { if(top == NULL) return; Node* tmp = top; top = top->next; delete tmp; } int Top() { if(top!=NULL) return top->data; } void PrintStack() { if(top == NULL) return; Node* tmp = top; while(tmp != NULL) { cout << tmp->data << " "; tmp = tmp->next; } cout << endl; }
相关文章推荐
- 49. 3种方法实现复杂链表的复制[clone of complex linked list]
- 双向链表的C++实现 Implement of Doubly Linked List
- 单链表的C++实现 Implement of Linked List
- 用链表实现带菜单功能的一元多项式的基本操作 (Use linked list to realize the basic operation of a one-dimensional polynom)
- LinkedList : 双向链表与实现
- MyLinkedList(链表的实现)
- C实现 LeetCode->Linked List Cycle 双指针大法)(单链表是否有环 并计算环长度)
- 简单实现 linkedList 双向链表
- [CareerCup] 2.2 Kth to Last Element of Linked List 链表的倒数第k个元素
- [leetcode]Reverse Linked List II (反转链表值 C语言实现)
- C实现 LeetCode->Reverse Linked List II (双指针大法)(单链表反转)
- Data structure-3 单链表LinkedList--Java语言实现
- LinkedList---链表各种方法的实现
- 372. 在O(1)时间复杂度删除链表节点 (delete-node-in-the-middle-of-singly-linked-list)(c++)----lintcode面试题之链表
- 用数组实现栈 Array implementation of stacks
- Reverse Second half of LinkedList Java实现
- C语言实现单链表(LinkedList)
- important points of linked list and stacks
- 基于jdk的list 和 队列 linkedList 和父亲长子兄弟链表模型 实现的 树 的前序遍历,后序遍历和层次遍历
- 【数据结构】链表LinkedList分析与关键实现