Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream in ("input.txt");
- ofstream out ("output.txt");
- class Queue {
- struct Element {
- int inf;
- Element *next;
- Element(int x) : inf(x), next(0) {}
- };
- Element *head, *tail;
- public:
- Queue() : head(0), tail(0) {}
- bool empty() { return head == 0;}
- int get() { if (empty()) return 0; else
- {
- Element *t = head;
- int i = t->inf;
- head = t->next;
- if (head == NULL) tail = NULL;
- delete t;
- return i;}}
- void pop() {
- //if (empty()) return 0;
- Element *t = head;
- head = head->next;
- if (head == NULL) tail = NULL;
- delete t;}
- int front() {
- return head->inf;}
- void push(int data){
- Element *t = tail;
- tail = new Element(data);
- if (!head) head = tail; else t->next = tail;}
- };
- int main (){
- Queue Q;
- int x, val;
- in >> x;
- while (in >> val)
- Q.push(val);
- in.close();
- while (!Q.empty()){
- if (Q.front() == x) { Q.pop(); continue;} else
- out << Q.front() << '\t';
- Q.pop();}
- out.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment