Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. // List1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8. struct list
  9. {
  10. int inf;
  11. list*next;
  12. };
  13. void init(list**begin,list**end, int n);
  14. void output(list*begin);
  15. void add_begin(list**begin, int n);
  16. void add_end(list**begin, int n);
  17. void add_prev(list**begin, int n, int x);
  18. void add_next(list**begin, int n, int x);
  19. int main()
  20. {
  21. list*begin = NULL, *end = NULL;
  22. int n, k, el, x;
  23. do
  24. {
  25. cout << "n = ";
  26. cin >> n;
  27. init(&begin, &end, n);
  28. cout << "Next ? ";
  29. cin >> k;
  30. } while (k != 0);
  31. cout << "el = ";
  32. cin >> el;
  33. add_begin(&begin, el);
  34. cout << "el = ";
  35. cin >> el;
  36. add_end(&begin, el);
  37. cout << "el = ";
  38. cin >> el;
  39. cout << "x = ";
  40. cin >> x;
  41. add_prev(&begin, el, x);
  42. cout << "el = ";
  43. cin >> el;
  44. cout << "x = ";
  45. cin >> x;
  46. add_next(&begin, el, x);
  47. cout << "List: ";
  48. output(begin);
  49. system("pause");
  50. return 0;
  51. }
  52. void init(list**begin, list**end, int n)
  53. {
  54. list*t = new list;
  55. if (*begin == NULL)
  56. {
  57. t->inf = n;
  58. t->next = NULL;
  59. *begin = *end = t;
  60. }
  61. else
  62. {
  63. t->inf = n;
  64. t->next = NULL;
  65. (*end)->next = t;
  66. *end = t;
  67. }
  68. }
  69. void output(list*begin)
  70. {
  71. list*t = new list;
  72. t = begin;
  73. while (t != NULL)
  74. {
  75. cout << t->inf << " ";
  76. t = t->next;
  77. }
  78. cout << endl;
  79. }
  80. void add_begin(list**begin, int n)
  81. {
  82. list*t = new list;
  83. t->inf = n;
  84. t->next = *begin;
  85. *begin = t;
  86. }
  87. void add_end(list**begin, int n)
  88. {
  89. list*t = new list;
  90. t = *begin;
  91. while (t != NULL)
  92. {
  93. t = t->next;
  94. }
  95. list*a = new list;
  96. a->next = NULL;
  97. a->inf = n;
  98. t->next = a;
  99. }
  100. void add_prev(list**begin, int n, int x)
  101. {
  102.  
  103. }
  104. void add_next(list**begin, int n, int x)
  105. {
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement