为说明思想,假设队列.栈都很大,不会出现满的情况. 1. 两个栈实现队列 //前提已知: struct Stack { int top; //栈顶指针 int stacksize;//栈的大小 int *s; //栈底指针 }; void InitStack(Stack *s): void Push(Stack *s, int k); int Pop(*s); int IsStackEmpty(*s); int IsStackFull(*s); 实现一 思路 s1是入栈的,s2是出栈的. 入队列…
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all o…
在前面几篇博文中曾经提到链表(list).队列(queue)和(stack),为了更加系统化,这里统一介绍着三种数据结构及相应实现. 1)链表 首先回想一下基本的数据类型,当需要存储多个相同类型的数据时,优先使用数组.数组可以通过下标直接访问(即随机访问),正是由于这个优点,数组无法动态添加或删除其中的元素,而链表弥补了这种缺陷.首先看一下C风格的单链表节点声明: // single list node define typedef struct __ListNode { int val; st…