int main(){
cout << "***** stack の char での利用 *****\n";
stack<char> s1;
s1.push('t');
s1.push('s');
s1.push('e');
s1.push('T');
for(int i=0; i<4; i++) cout << "s1をポップする: " << s1.pop() << "\n";
cout << "***** stack の int での利用 *****\n";
stack<int> s2;
s2.push(3);
s2.push(2);
s2.push(1);
s2.push(0);
for(int i=0; i<4; i++) cout << "s2をポップする: " << s2.pop() << "\n";
return 0;
}
|
#include <iostream>
using namespace std;
// (※) ここに node クラスと list クラスの定義を挿入
class queue{
list l;
public:
void push(int i);
int pop();
};
void queue::push(int i){
// (※) 記述
}
int queue::pop(){
// (※) 記述
}
int main(){
queue q;
for(int i=0 ; i<10 ; i++){
q.push(i);
}
for(int i=0 ; i<10 ; i++){
cout << q.pop() << "\n";
}
return(0);
}
|
----data access with the iterator 1 D 2 A 4 F 5 B 8 A 9 C ----data access with the key key=5, data=B ----used as a Priority Queue D A F B A C |