Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Node
- {
- int var;
- Node *Next;
- };
- typedef Node *PNode;
- bool Check_Empty(PNode Head, PNode Tail)
- {
- if(Head == NULL && Tail == NULL) return true;
- else return false;
- }
- void Output(PNode Head)
- {
- PNode p = Head;
- if(Head != NULL)
- {
- cout << "Текущий список:" << endl;
- while(p != NULL)
- {
- cout << p -> var << " ";
- p = p -> Next;
- }
- }
- else cout << "Список пуст.";
- cout << endl;
- }
- void Push(PNode &Head, PNode &Tail, int x)
- {
- PNode p;
- p = new Node;
- p -> var = x;
- p -> Next = NULL;
- if(Head != NULL)
- {
- Tail -> Next = p;
- Tail = p;
- }
- else
- {
- Head = p;
- Tail = p;
- }
- cout << "ok" << endl;
- }
- void Pop(PNode &Head, bool Del)
- {
- int t = Head -> var;
- if(Del)
- {
- PNode Old = Head;
- Head = Head -> Next;
- delete Old;
- }
- cout << t << endl;
- }
- int Size(PNode Head)
- {
- PNode p = Head;
- int n = 0;
- while(p != NULL)
- {
- n++;
- p = p -> Next;
- }
- return n;
- }
- void Clear(PNode &Head)
- {
- while(Head != NULL)
- {
- PNode Old = Head;
- Head = Head -> Next;
- delete Old;
- }
- cout << "ok" << endl;
- }
- void main()
- {
- PNode Head = NULL;
- PNode Tail = NULL;
- string operation;
- while(cin >> operation)
- {
- if(operation == "check") Output(Head);
- if(operation == "push")
- {
- int x;
- cin >> x;
- Push(Head, Tail, x);
- }
- if(operation == "pop")
- {
- if(Check_Empty(Head, Tail))
- cout << "error" << endl;
- else Pop(Head, true);
- }
- if(operation == "front")
- {
- if(Check_Empty(Head, Tail))
- cout << "error" << endl;
- else Pop(Head, false);
- }
- if(operation == "size") cout << Size(Head) << endl;
- if(operation == "clear") Clear(Head);
- if(operation == "exit")
- {
- cout << "bye" << endl;
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement