zl程序教程

您现在的位置是:首页 >  后端

当前栏目

hdu1702 list or stack+queue

List or Queue Stack
2023-09-11 14:16:05 时间

http://acm.hdu.edu.cn/showproblem.php?pid=1702

#include iostream 

#include cstdio 

#include cstring 

#include list 

using namespace std;

int main()

 // freopen("1.txt","r",stdin);

 int n;

 scanf("%d", 

 while(n--)

 int m,i,x;

 list int 

 li.clear();

 char s[10],ss[10];

 scanf("%d %s", m,s);

 if(strcmp(s,"FIFO")==0)

 for(i=0; i i++)

 scanf("%s",ss);

 if(strcmp(ss,"IN")==0)

 cin x;

 li.push_back(x);

 else

 if(li.empty())

 cout "None" endl;

 else

 cout li.front() endl;

 li.pop_front();

 else

 for(i=0; i i++)

 scanf("%s",ss);

 if(strcmp(ss,"IN")==0)

 cin x;

 li.push_back(x);

 else

 if(li.empty())

 cout "None" endl;

 else

 cout li.back() endl;

 li.pop_back();

 return 0;

#include iostream 

#include cstdio 

#include cstring 

#include stack 

#include queue 

using namespace std;

int main()

 // freopen("1.txt","r",stdin);

 int n,x,m;

 char s[10],ss[10];

 stack int 

 queue int 

 scanf("%d", 

 while(n--)

 while(!st.empty())

 st.pop();

 while(!q.empty())

 q.pop();

 scanf("%d %s", m,s);

 if(strcmp(s,"FILO")==0)

 for(int i=0; i i++)

 scanf("%s",ss);

 if(strcmp(ss,"IN")==0)

 cin x;

 st.push(x);

 else

 if(st.empty())

 cout "None" endl;

 else

 cout st.top() endl;;

 st.pop();

 else

 for(int i=0; i i++)

 scanf("%s",ss);

 if(strcmp(ss,"IN")==0)

 cin x;

 q.push(x);

 else

 if(q.empty())

 cout "None" endl;

 else

 cout q.front() endl;

 q.pop();

 return 0;


Java编程之LinkedList+Vector+Stack+Queue Vector类 1.java.util包 2.是ArrayList集合的早期版本 (StringBuffer早期 StringBuilder后来) Vector底层也是利用(动态)数组的形式存储 Vector是线程同步的(synchronized) 安全性高 效率低 3.扩容方式与ArrayList不同 默认是扩容2倍 可以通过构造方法创建对象时修改这一机制 4.构造方法 5.常用方法 Stack类 栈 1.java.util包 2.构造方法只有一个无参数 3.除了继承自Vacton类
Vector和Stack源码分析/List集合的总结 这篇文章算是在这list接口下的集合的最后一篇了,前面ArrayList、LinkedList都已经讲解完了,剩下就Vector和Vector的子类Stack啦。继续努力。一步一个脚印,
给出 -21- 10- 4- 5, tail connects to node index 1,返回 true。 这里解释下,题目的意思,在英文原题中,tail connects to node index 1 表示的是节点 5 还要链接回索引号 为 1 的节点。