Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*6. Ñîçäàòü ñïèñîê èç öåëûõ ÷èñåë. Èñêëþ÷èòü èç ñïèñêà âñå ýëåìåíòû, ðàâíûå õ.*/
- #include <fstream>
- using namespace std;
- ifstream in ("input.txt");
- ofstream out ("output.txt");
- class Stack {
- struct Element {
- int inf;
- Element *next;
- Element(int x, Element *p) : inf(x), next(p) {}
- };
- Element *head;
- public:
- Stack() : head(0) {}
- bool empty() {
- return head == 0; }
- int pop() {
- if (empty()) { return 0;}
- Element *r = head;
- int i = r->inf;
- head = r->next;
- delete r;
- return i;}
- void push(int data) { head = new Element(data, head);}
- int top() { if (empty()) return 0; else return head->inf;}
- };
- int main(){
- Stack Stc;
- int x, val;
- in >> x;
- while (in >> val)
- Stc.push(val);
- in.close();
- while (!Stc.empty()){
- if (Stc.top() == x) { Stc.pop(); continue;} else
- out << Stc.top() << '\t';
- Stc.pop();}
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement