Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. class queue
  5. {
  6. private:
  7.     struct q{
  8.         int key;
  9.         q *next;
  10.     }*first,*last;
  11. public:
  12.     int size;
  13.     queue(){
  14.         first=NULL;
  15.         last=NULL;
  16.         size=0;
  17.     }
  18.     void push(int n)
  19.     {
  20.     q *p=last;
  21.     last=new q;
  22.     last->key=n;
  23.     last->next=NULL;
  24.     if(p!=NULL){
  25.         p->next=last;
  26.         size++;
  27.     }
  28.     if(first=NULL)
  29.         first=last;
  30.     }
  31.     int empty()
  32.     {
  33.     if(first==last)
  34.         return 1;
  35.     else
  36.         return 0;
  37.     }
  38.     int pop(int n){
  39.     if(!empty())
  40.     {
  41.         n=first->key;
  42.         q *p=first;
  43.         first=first->next;
  44.         delete p;
  45.         return 1;
  46.         size--;
  47.     }else
  48.         return 0;
  49.     }
  50. };
  51. queue q1;
  52. queue q2;
  53. void data1()
  54. {
  55.     fstream fp("q1.txt", ios::in);
  56.     int n;
  57.     while(fp.eof()){
  58.         fp >> n;
  59.         q1.push(n);
  60.     }
  61. }
  62. void data2()
  63. {
  64.     fstream fp("q2.txt", ios::in);
  65.     int n;
  66.     while(fp.eof()){
  67.         fp >> n;
  68.         q2.push(n);
  69.     }
  70. }
  71. void add(int a,queue q)
  72. {
  73.     if(a==1){
  74.      system("cls");
  75.      data1();
  76.      cout<<"Informaciqta ot failat e prochetena";
  77.      cout<<endl;
  78.      system("pause");
  79.      system("cls");
  80.     }else{
  81.         system("cls");
  82.         data2();
  83.         cout<<"Informaciqta ot failat e prochetena";
  84.         cout<<endl;
  85.         system("pause");
  86.         system("cls");
  87.     }
  88. }
  89. void output(int nmbr,queue q)
  90. {
  91.     int element;
  92.     system("cls");
  93.     if(q.empty()){
  94.         cout<<" Opashkata e prazna";
  95.     }else{
  96.         cout<<"Vavedenite elementi v opashka "<<nmbr<<" sa: "<<endl;
  97.         while(q.size){
  98.             q.pop(element);
  99.             cout<<element<<" ";
  100.             }
  101.         }
  102.         cout<<endl;
  103.         system("pause");
  104.         system("cls");
  105. }
  106. int menu(){
  107.     int choise;
  108.     cout<<"************************************************"<<endl;
  109.     cout<<"** 1. Dobavqne na elementi v opashkata 1.     **"<<endl;
  110.     cout<<"** 2. Dobavqne na elementi v opashkata 2.     **"<<endl;
  111.     cout<<"** 3. Izvejdane na elementi ot opashkata 1.   **"<<endl;
  112.     cout<<"** 4. izvejdane na elementi ot opashkata 2.   **"<<endl;
  113.     cout<<"** 5. Izhod                                   **"<<endl;
  114.     cout<<"************************************************"<<endl;
  115.     cin>>choise;
  116.     return choise;
  117. }
  118. int main()
  119. {
  120.     int otg;
  121.     while(true){
  122.         otg=menu();
  123.         switch(otg){
  124.             case 1:
  125.             add(1,q1);break;
  126.         case 2:
  127.             add(2,q2);break;
  128.         case 3:
  129.             output(1,q1);break;
  130.         case 4:
  131.             output(2,q2);break;
  132.         case 5:
  133.             return 0;break;
  134.         }
  135.     }
  136. }
Add Comment
Please, Sign In to add comment