Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <math.h>
- using namespace std;
- struct TNode
- {
- int data;
- TNode* prev=NULL;
- };
- int pop(TNode *&head)
- {
- int ret = head->data;
- TNode *p = head;
- head = head->prev;
- delete(p);
- return ret;
- }
- void push (int data, TNode*&head)
- {
- TNode *p = new TNode;
- p->data = data;
- p->prev = head;
- head = p;
- }
- int main()
- {
- TNode* mainstack = NULL, *odd = NULL, *even = NULL;
- ifstream in("in.txt");
- ofstream out("out.txt");
- int tmp;
- while(in.good())
- {
- in>>tmp;
- push(tmp, mainstack);
- }
- pop(mainstack);
- while(mainstack)
- {
- if(mainstack->data%2==0) push(mainstack->data,even);
- else push(mainstack->data,odd);
- mainstack = mainstack->prev;
- }
- while(even)
- {
- out<<pop(even)<<" ";
- }
- out<<endl;
- while(odd)
- {
- out<<pop(odd)<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement