Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct stack
- {
- struct stack *prev;
- struct stack *next;
- int l,r;//позиции скобок
- }*head;
- void push(struct stack*j)
- {
- if(head==0)
- head = j;
- else {
- head->next = j;
- j->prev=head;
- head = j;
- }
- }
- void pop()
- {
- if(head!=0)
- {
- head=head->prev;
- free(head->next);
- head->next = 0;
- }
- else
- return;
- }
- void vivod()
- {
- struct stack *i;
- for(i=head;i!=0;i=i->prev)
- printf("(%d,%d)",i->l,i->r);
- }
- main(void)
- {
- head = 0;
- char m[60];
- int *x,*y;
- int i=0;
- int g;
- int k,q,w;
- FILE *f;
- f = fopen("text.txt","r");
- fscanf(f,"%s",m);
- g = strlen(m);
- for(i=0;i<g;i++)
- if(m[i]='(')
- k++;
- x = (int*)(malloc(sizeof(int)*(k)));
- y = (int*)(malloc(sizeof(int)*(k)));
- for(i=0,q=0,w=0;i<g;i++)
- {if(m[i]=='(')
- x[q]=i, q++;
- if(m[g - i - 1]==')')
- y[w]= g - i - 1,w++;}
- for(i=0;i<k;i++)
- {
- struct stack*name = (struct stack*)(malloc(sizeof(struct stack)));
- name->l=x[i];
- name->r=y[i];
- name->next = 0;
- name->prev=0;
- push(name);
- }
- vivod();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement