Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct comp
- {
- int data;
- comp* next;
- };
- comp* addstack(comp* top, int inf)
- {
- comp* spt = new comp;
- spt->data = inf;
- spt->next = top;
- return spt;
- }
- int chek(comp* top) {
- comp* tmp = top;
- while (tmp) {
- if (tmp->data < 0) return 1;
- tmp = tmp->next;
- }
- return 0;
- }
- void s_print(comp* top) {
- comp* tmp = top;
- while (tmp) {
- cout << tmp->data << ' ';
- tmp = tmp->next;
- }
- }
- void delstack(comp* top) {
- comp* tmp; int data;
- while (top) {
- tmp = top;
- data = top->data;
- cout << data << ' ';
- top = top->next;
- delete tmp;
- }
- }
- int main() {
- setlocale(LC_ALL, "RU");
- comp* top = NULL;
- int n, value;
- cout << "Введите количество элементов стека: ";
- cin >> n;
- cout << "Введите элементы стека: ";
- for (int i = 0; i < n; i++) {
- cin >> value;
- top = addstack(top, value);
- }
- s_print(top);
- chek(top);
- int e = chek(top);
- if (e == 1) cout << "\nесть отрицательные числа";
- else cout << "\nнет отрицательных чисел";
- cout << endl;
- delstack(top);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement