Advertisement
fabis_sparks

FromXto1

Jun 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. // Test2.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cstdlib>
  7.  
  8. using namespace std;
  9. struct list {
  10.     int x;
  11.     list* next;
  12. };
  13. list* creat(int);
  14. void print(list *);
  15. int main()
  16. {
  17.     struct list *head;
  18.     int n;
  19.     cin >> n;
  20.     head = creat(n);
  21.     print(head);
  22.     system("pause");
  23.  
  24. }
  25.  
  26. list* creat(int n)
  27. {
  28.     list *cur, *first;
  29.     if (n) first = new list;
  30.     first->x = n;cur = first;n--;
  31.     while (n > 0)
  32.     {
  33.         cur->next = new list;
  34.         cur = cur->next;
  35.         cur->x = n;
  36.         cur->next = NULL;
  37.         n--;
  38.        
  39.     }
  40.     return first;
  41. }
  42. void print(list *cur) {
  43.     while (cur->next) {
  44.         cout << cur->x << '\t';
  45.         cur = cur->next;
  46.     }
  47.     cout << cur->x;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement