码迷,mamicode.com
首页 > 其他好文 > 详细

手写栈,队列

时间:2017-04-30 22:46:56      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:one   ret   pre   oid   []   tac   play   队列   splay   

技术分享
 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

 

手写栈,队列

标签:one   ret   pre   oid   []   tac   play   队列   splay   

原文地址:http://www.cnblogs.com/mjtcn/p/6790458.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!