Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- class queue
- {
- private:
- struct q{
- int key;
- q *next;
- }*first,*last;
- public:
- int size;
- queue(){
- first=NULL;
- last=NULL;
- size=0;
- }
- void push(int n)
- {
- q *p=last;
- last=new q;
- last->key=n;
- last->next=NULL;
- if(p!=NULL){
- p->next=last;
- size++;
- }
- if(first=NULL)
- first=last;
- }
- int empty()
- {
- if(first==last)
- return 1;
- else
- return 0;
- }
- int pop(int n){
- if(!empty())
- {
- n=first->key;
- q *p=first;
- first=first->next;
- delete p;
- return 1;
- size--;
- }else
- return 0;
- }
- };
- queue q1;
- queue q2;
- void data1()
- {
- fstream fp("q1.txt", ios::in);
- int n;
- while(fp.eof()){
- fp >> n;
- q1.push(n);
- }
- }
- void data2()
- {
- fstream fp("q2.txt", ios::in);
- int n;
- while(fp.eof()){
- fp >> n;
- q2.push(n);
- }
- }
- void add(int a,queue q)
- {
- if(a==1){
- system("cls");
- data1();
- cout<<"Informaciqta ot failat e prochetena";
- cout<<endl;
- system("pause");
- system("cls");
- }else{
- system("cls");
- data2();
- cout<<"Informaciqta ot failat e prochetena";
- cout<<endl;
- system("pause");
- system("cls");
- }
- }
- void output(int nmbr,queue q)
- {
- int element;
- system("cls");
- if(q.empty()){
- cout<<" Opashkata e prazna";
- }else{
- cout<<"Vavedenite elementi v opashka "<<nmbr<<" sa: "<<endl;
- while(q.size){
- q.pop(element);
- cout<<element<<" ";
- }
- }
- cout<<endl;
- system("pause");
- system("cls");
- }
- int menu(){
- int choise;
- cout<<"************************************************"<<endl;
- cout<<"** 1. Dobavqne na elementi v opashkata 1. **"<<endl;
- cout<<"** 2. Dobavqne na elementi v opashkata 2. **"<<endl;
- cout<<"** 3. Izvejdane na elementi ot opashkata 1. **"<<endl;
- cout<<"** 4. izvejdane na elementi ot opashkata 2. **"<<endl;
- cout<<"** 5. Izhod **"<<endl;
- cout<<"************************************************"<<endl;
- cin>>choise;
- return choise;
- }
- int main()
- {
- int otg;
- while(true){
- otg=menu();
- switch(otg){
- case 1:
- add(1,q1);break;
- case 2:
- add(2,q2);break;
- case 3:
- output(1,q1);break;
- case 4:
- output(2,q2);break;
- case 5:
- return 0;break;
- }
- }
- }
Add Comment
Please, Sign In to add comment