Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class node
- {
- public:
- int num;
- node *next=NULL;
- };
- class queue
- {
- public:
- queue(){ cout << "***head= " << head << endl; }
- void push(int);
- void pop();
- private:
- node *head = new(node);
- };
- void queue::push(int n)
- {
- node *pos=head;
- while (pos->next!=NULL)
- {
- pos = pos->next;
- }
- pos->next = new(node);
- pos->next->num = n;
- cout << "***push " << n << " to " << pos->next << endl;
- }
- void queue::pop()
- {
- if (head->next == NULL)
- {
- cout << "empty queue!\n";
- return;
- }
- node *del=head->next;
- head->next = head->next->next;
- cout << "pop " << del->num <<" frome "<< del << endl;
- delete(del);
- }
- void main()
- {
- cout << "new qu1\n";
- queue qu1;
- cout << "start push\n";
- qu1.push(1);
- qu1.push(2);
- qu1.push(3);
- qu1.push(4);
- cout << "start pop\n";
- qu1.pop();
- qu1.pop();
- qu1.pop();
- qu1.pop();
- qu1.pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement