Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- node *next = NULL;
- int data;
- };
- void add(int num, node **head)
- {
- node *tmp = new node;
- if (*head == NULL)
- {
- *head = tmp;
- tmp->data = num;
- }
- else
- {
- tmp->data = num;
- tmp->next = *head;
- *head = tmp;
- }
- }
- void show(node *head)
- {
- node *tmp = head;
- while (tmp != NULL)
- {
- cout << "data: "<<tmp->data<<endl;
- tmp = tmp->next;
- }
- }
- int main()
- {
- setlocale(0, "");
- node *head = NULL;
- int n;
- cout << "Количество элементов стека: ";
- cin >> n;
- int num;
- cout << "Вводите данные: ";
- for (int i = 0; i < n; i++)
- {
- cout << "Информация: ";
- cin >> num;
- add(num, &head);
- }
- system("cls");
- show(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement