Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- ifstream in("in2.txt");
- ofstream out("out1.txt");
- template <class Item> //класс-шаблон очередь
- class Stack
- {
- struct Element
- {
- Item inf;
- Element* next;
- Element(Item x,Element *p) :inf(x), next(p)
- {
- }
- };
- Element* head;
- public:
- Stack():head(0)
- {
- }
- bool Empty()
- {
- return head == 0;
- }
- Item Pop()
- {
- if (Empty())
- {
- cout <<"Error"<< std::endl;
- }
- else {
- Element* r = head;
- Item i = r->inf;
- head = r->next;
- delete r;
- return i;
- }
- }
- void Push(Item data) {
- head = new Element(data, head);
- }
- int Top()
- {
- if (Empty()) {
- return 0;
- }
- else{
- return head->inf; //иначе новый узел помещаем в конец очереди
- }
- }
- };
- int main()
- {
- Stack <int> I;
- Stack<int>J;
- int i,x,c;
- if(!in) out<<"ERR";
- while(in>>i){
- I.Push(i);
- cout<<i;
- }
- in.close();
- x=INT_MAX;
- while(!I.Empty()){
- c=I.Pop();
- if (c<x)x=c;
- cout<<c;
- J.Push(c);}
- while(!J.Empty()){
- c=J.Pop();
- cout<<c;
- if(c!=x)I.Push(c);}
- while(!I.Empty()){
- out<<I.Pop();}
- out.close();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement