Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ЭКЗ БИЛЕТ ЧАЕВСКОГО.cpp: определяет точку входа для консольного приложения.
- //Создать стеки для 7 элементов.Удалить все положительные и очистить память
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct stack {
- int inf;
- stack *next;
- };
- stack* AddNewStack(stack*&);
- void ReadStack(stack*&);
- stack* Delete(stack*&);
- int main()
- {
- stack*head = NULL, *temp;
- cout << "Vvedite colvo elementov v steke" << endl;
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- AddNewStack(*&head);
- }
- temp = head;
- cout << "Stek: " << endl;
- ReadStack(*&head);
- cout << endl;
- head = temp;
- stack* Zadanie(stack*&head);
- head = temp;
- cout << "Noviy Stek: " << endl;
- ReadStack(*&head);
- cout << endl;
- system("pause");
- return 0;
- }
- stack* AddNewStack(stack*&head)
- {
- stack*element = new stack;
- element->next = head;
- cin >> element->inf;
- head=element;
- return head;
- }
- void ReadStack(stack*&head)
- {
- stack*tmp = head;
- while (head != NULL)
- {
- cout << head->inf << " ";
- head = head->next;
- }
- head = tmp;
- cout << endl;
- return;
- }
- stack* Delete(stack*&head)
- {
- while (head != NULL)
- {
- stack*tmp = head;
- head = head->next;
- delete tmp;
- }
- delete head;
- return NULL;
- }
- stack* Zadanie(stack*&head)
- {
- while (head != NULL)
- {
- if (head->inf > 0)
- {
- stack*tmp = head;
- head = head->next;
- delete tmp;
- }
- else
- {
- head = head->next;
- }
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement