Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- class Node
- {
- public:
- char c;
- Node *next;
- Node(char cc) { c = cc; next = nullptr; };
- };
- void Print(Node *s)
- {
- if (s == nullptr) {
- return;
- }
- Node *p;
- p = s;
- while (p != nullptr)
- {
- cout << p->c;
- p = p->next;
- }
- cout << endl;
- }
- int main()
- {
- char c;
- Node *start = nullptr;
- Node *end = nullptr;
- int i = 0;
- while (i++ < 10)
- {
- c = _getch();
- Node *p = new Node(c);
- if (start == nullptr)
- {
- start = p;
- end = start;
- }
- else
- {
- end->next = p;
- end = p;
- }
- }
- Print(start);
- cout << endl;
- Node *stop = end;
- while (stop != start) {
- Node *p;
- p = start;
- while (p->next != stop)
- {
- p = p->next;
- }
- cout << p->next->c;
- stop = p;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement