数组、链表实现队列、栈-->http://acm.sdut.edu.cn/BBS/read.php?tid=3461 

粘一个看得懂,感觉比较实用的(其实别的都看不懂...)

 

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     int a[1000],i,top,end1,b[1000],end2;
 6     int m,n;
 7     char str[8];
 8     top=end1=end2=0;
 9     scanf("%d %d",&n,&m);
10     for(i=0;i<n;i++)
11     scanf("%d",&a[i]);
12 
13     for(i=0;i<m;i++)
14     {
15         scanf("%s",&str);
16       if(strcmp(str,"push")==0)
17       {
18         b[end1++]=a[end2++];
19         printf("%d\n",b[end1-1]);
20       }
21       else if(strcmp(str,"pop")==0)
22       {
23         top++;
24       }
25       else if(strcmp(str,"front")==0)
26        {
27         printf("%d\n",b[top]);
28        }
29     }
30 
31 
32     return 0;
33 
34 
35 }

 

posted on 2011-08-20 20:27  追逐.  阅读(202)  评论(0编辑  收藏  举报