Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Test2.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct list {
- int x;
- list* next;
- };
- list* creat(int);
- void print(list *);
- int main()
- {
- struct list *head;
- int n;
- cin >> n;
- head = creat(n);
- print(head);
- system("pause");
- }
- list* creat(int n)
- {
- list *cur, *first;
- if (n) first = new list;
- first->x = n;cur = first;n--;
- while (n > 0)
- {
- cur->next = new list;
- cur = cur->next;
- cur->x = n;
- cur->next = NULL;
- n--;
- }
- return first;
- }
- void print(list *cur) {
- while (cur->next) {
- cout << cur->x << '\t';
- cur = cur->next;
- }
- cout << cur->x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement