Last active
May 25, 2017 09:16
-
-
Save skhozinova/4fe1bcca272d7246f03965cd6db7fa0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 | |
4 | |
5 | |
1 | |
6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61542 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
struct stack //описание стека stack | |
{ | |
int item; | |
stack *next; | |
}; | |
stack *init_stack() //инициализация стека | |
{ | |
return NULL; | |
} | |
void push(stack *&next,int item) //добавление элемента в стек. Передача по ссылке!! Значение аргумента меняется!! | |
{ | |
stack *r; | |
r=new stack; | |
r->item=item; | |
r->next=next; | |
next=r; | |
} | |
int pop(stack *&next) //выбор верхнего элемента из стека | |
{ | |
stack *r=next; | |
int x=r->item; | |
next=r->next; | |
delete r; | |
return x; | |
} | |
int peek(stack *next) //просмотр верхнего элемента стека | |
{ | |
return next->item; | |
} | |
int empty_stack(stack *next) //определение пустоты стека | |
{ | |
if(next==0) | |
return 1; | |
else | |
{ | |
return 0; | |
} | |
} | |
int kek(stack *&next) //выбор верхнего элемента из стека | |
{ | |
stack *r=next; | |
int x=r->item; | |
next=r->next; | |
return x; | |
} | |
int main(void) | |
{ | |
FILE *h=fopen("input.txt","r"); | |
FILE *g=fopen("output.txt","w"); | |
int x, min; | |
stack *head=init_stack(); //инициализация стека | |
while (!feof(h)) //пока не достигнут конец файла h | |
{ | |
fscanf(h,"%d",&x); //читаем целое число из файла в переменную x | |
push(head,x); //записываем значение x в стек | |
x=kek(head); | |
if (min=x) | |
{ | |
delete head; | |
} | |
} | |
while (!empty_stack(head)) //пока стек не пуст | |
{ | |
x=pop(head); //извлекаем верхний элемент из стека | |
fprintf(g,"%d",x);//записываем его в файл g | |
} | |
fcloseall(); //завершаем работу с файлами | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment