Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // saa_zadacha_stek.cpp : This file contains the 'main' function. Program execution begins and ends there.
- // Да се създаде динамичен стек съдържащ положителни числа и извеждаме неговоро съдържание
- #include "pch.h"
- #include <iostream>
- #include <conio.h>
- using namespace std;
- struct S
- {
- int key;
- S *next;
- }*start = NULL;
- void push(int n)
- {
- S *p;
- p = start;
- start = new S;
- start->key = n;
- start->next = p;
- }
- int pop(int &n)
- {
- S *p;
- if (start)
- {
- p = start;
- n = start->key;
- start = start->next;
- delete p;
- return 1;
- }
- else
- return 0;
- }
- int main()
- {
- int num, br, A, n;
- do {
- cout << "Vuvedi stoinost na elementite v stack-a: ";
- cin >> num;
- if ( num > 0)
- push(num);
- } while (num);
- /*for (int i = 0; i < br; i++)
- {
- cout << "Vuvedi stoinost: ";
- cin >> num;
- push(num);
- }*/
- cout << "Vuvedi stoinost za N: " << endl;
- cin >> n;
- for (int i = 0; i < n - 1; i++)
- pop(num);
- cout << "Vuvedi stoinost za A: ";
- cin >> A;
- start->key = A;
- cout << "Rezult: " << endl;
- while (start != NULL)
- {
- cout << start->key<<endl;
- pop(start->key);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement