Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct List
  4. {
  5. int inf;
  6. List* link;
  7. }*head;
  8. void Create(List*& head)
  9. {
  10. head = NULL;
  11. }
  12. void Input(int x, List*& list)
  13. {
  14. List* q = new List;
  15. q->inf = x;
  16. q->link = list;
  17. list = q;
  18. }
  19. void Print(List*& list)
  20. {
  21. while (head != NULL)
  22. {
  23. cout << head->inf << endl;
  24. head = head->link;
  25. }
  26. }
  27. int main()
  28. {
  29. int n, x;
  30. List* list;
  31. Create(head);
  32. cout << "Enter the count of numbers: ";
  33. cin >> n;
  34. for (int i = 0; i < n; i++)
  35. {
  36. cin >> x;
  37. if (i == 0)
  38. {
  39. head->inf = x;
  40. head->link = NULL;
  41. }
  42. Input(x, list);
  43. }
  44. cout << head->inf;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement