Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- struct stack
- {
- int inf;
- stack *next;
- };
- stack *init_stack()
- {
- return 0;
- }
- void push(stack *&s, int item)
- {
- stack *r;
- r = new stack;
- r->inf = item;
- r->next = s;
- s = r;
- }
- int pop(stack *&s)
- {
- stack *r = s;
- int st;
- st = r->inf;
- s = s->next;
- free(r);
- return st;
- }
- int peek(stack* s)
- {
- return s->inf;
- }
- int empty_stack(stack* &s)
- {
- return (s) ? 0 : 1;
- }
- int main()
- {
- int i=0, k;
- char c;
- FILE *fin, *f1;
- fin = fopen("data.txt", "r");
- f1 = fopen("dataout.txt", "w");
- stack *head = init_stack();
- if (fin != NULL)
- {
- while (!feof(fin))
- {
- fscanf(fin, "%d", &i);
- push(head, i);
- }
- i = pop(head);
- while (!empty_stack(head))
- {
- k = pop(head);
- if (i != k)
- {
- fprintf(f1, "%d ", i);
- i = k;
- }
- }
- fprintf(f1, "%d ", i);
- }
- else printf("not today");
- system("pause");
- fcloseall();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement