Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "string"
- #include "math.h"
- using namespace std;
- struct node
- {
- node *next = NULL;
- node *prev = NULL;
- int data;
- };
- void add(int x, node **head)
- {
- node *tmp = new node;
- if (*head == NULL)
- {
- *head = tmp;
- tmp->data = x;
- }
- else
- {
- node *top = *head;
- top->next = tmp;
- tmp->prev = top;
- tmp->data = x;
- *head = top;
- }
- }
- void show(node *head)
- {
- node *tmp = head;
- while (tmp)
- {
- cout << "Data: " << tmp->data << endl;
- tmp = tmp->prev;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "russian");
- node *head = NULL;
- int n;
- cout << "n = ";
- cin >> n;
- int xxx;
- for (int i = 0; i < n; i++)
- {
- cout << "Enter data: ";
- cin >> xxx;
- add(xxx, &head);
- }
- system("cls");
- cout << "clear" << endl;
- show(head);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement