Guest User

Untitled

a guest
Apr 30th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Student {
  6. char* name;
  7. int age;
  8. };
  9.  
  10. struct List {
  11. Student student;
  12. List* next;
  13. };
  14.  
  15. void Print(List *begin)
  16. {
  17. List* print = begin;
  18. while(print)
  19. {
  20. cout <<print->student.name<<"->"<<print->student.age<<endl;
  21. print = print->next;
  22. }
  23. cout<<"NULL"<<endl;
  24. }
  25. void AddNewElement(char* NewName, int NewAge)
  26. {
  27. end ->next = new List;
  28. end = end->next;
  29. end -> student.name = NewName;
  30. end -> student.age = NewAge;
  31. end ->next = NULL;
  32. }
  33. void Init(List **begin)
  34. {
  35. *begin = new List;
  36. (*begin) -> student.name = "Andrew";
  37. (*begin) -> student.age = 20;
  38. (*begin) -> next = NULL;
  39.  
  40. List* end = *begin;
  41.  
  42. AddNewElement("Petr", 19);
  43. }
  44. int main()
  45. {
  46. List *begin = NULL;
  47. Init(&begin);
  48. Print(begin);
  49. return 0;
  50. }
  51.  
  52. #include <iostream>
  53.  
  54. using namespace std;
  55.  
  56. struct Student {
  57. char* name;
  58. int age;
  59. };
  60.  
  61. struct List {
  62. Student student;
  63. List* next;
  64. };
  65.  
  66. void Print(List *begin)
  67. {
  68. List* print = begin;
  69. while(print)
  70. {
  71. cout <<print->student.name<<"->"<<print->student.age<<endl;
  72. print = print->next;
  73. }
  74. cout<<"NULL"<<endl;
  75. }
  76. void AddNewElement(List *end, char* NewName, int NewAge)
  77. {
  78. end ->next = new List;
  79. end = end->next;
  80. end -> student.name = NewName;
  81. end -> student.age = NewAge;
  82. end ->next = NULL;
  83. }
  84. List *Init(List **begin)
  85. {
  86. *begin = new List;
  87. (*begin) -> student.name = "Andrew";
  88. (*begin) -> student.age = 20;
  89. (*begin) -> next = NULL;
  90.  
  91. return *begin;
  92. }
  93. int main()
  94. {
  95. List *begin = NULL;
  96. List *end = Init(&begin);
  97. AddNewElement(end, "Petr", 19);
  98. Print(begin);
  99. return 0;
  100. }
  101.  
  102. Andrew->20
  103. Petr->19
  104. NULL
  105.  
  106. void AddNewElement(char* NewName, int NewAge)
  107. {
  108. end ->next = new List;
  109. end = end->next;
  110. end -> student.name = NewName;
  111. end -> student.age = NewAge;
  112. end ->next = NULL;
  113. }
Add Comment
Please, Sign In to add comment