首页 > 代码库 > 手写栈,队列

手写栈,队列

技术分享
 1 struct sta 2 { 3     int sz[100001]; 4     int top() 5     { 6         return sz[top]; 7     } 8     void push(int x){ 9          sz[++top]=x;10     }11     void pop(){12         if(top>0)13         top--;14     }15     void cl()16     {17         top=0;18     }19     int size(){20         return top;21     }22 }stack;23 24 stack
View Code
技术分享
 1 #define MAXN 10000 2 struct queue{ 3     int sz[10000]; 4     int head,tail; 5     queue() 6     { 7         head=0; 8         tail=0; 9     }10     queue()11     {12         head=0;13         tail=0;14         delete []sz;15     }16     int front()17     {18         if(!empty())19         return sz[head];20     }21     bool empty()22     {23         return (head>=0&&tail>=0&&head==tail||head>tail);24     }25     bool full()26     {27         return tail>=MAXN;28     }29     int push(int x)30     {31         if(!full())32         sz[tail++]=x;33     }34     void pop()35     {36         if(!empty())37             ++head;38     }39 }40 41 queue
View Code

 

手写栈,队列