Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. class Node
  7. {
  8. public:
  9. char c;
  10. Node *next;
  11. Node(char cc) { c = cc; next = nullptr; };
  12. };
  13.  
  14. void Print(Node *s)
  15. {
  16. if (s == nullptr) {
  17. return;
  18. }
  19. Node *p;
  20. p = s;
  21. while (p != nullptr)
  22. {
  23. cout << p->c;
  24. p = p->next;
  25. }
  26. cout << endl;
  27. }
  28.  
  29.  
  30. int main()
  31. {
  32. char c;
  33. Node *start = nullptr;
  34. Node *end = nullptr;
  35. int i = 0;
  36. while (i++ < 10)
  37. {
  38. c = _getch();
  39. Node *p = new Node(c);
  40. if (start == nullptr)
  41. {
  42. start = p;
  43. end = start;
  44. }
  45. else
  46. {
  47. end->next = p;
  48. end = p;
  49. }
  50. }
  51. Print(start);
  52. cout << endl;
  53. Node *stop = end;
  54. while (stop != start) {
  55. Node *p;
  56. p = start;
  57. while (p->next != stop)
  58. {
  59. p = p->next;
  60. }
  61. cout << p->next->c;
  62. stop = p;
  63. }
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement