Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Zadanie 13 A 3
- // szczegolowy szkic
- // T(n) = Theta(n)
- // M(n) = O(n)
- void popraw(lista* l) {
- lista* a;
- lista* stack = empty();
- lista* w;
- lista* tmp;
- a->next = l;
- w = a;
- while (w) {
- if (w->next) {
- if (w->next->value == '(') {
- push(&stack, w);
- } else {
- if (is_empty(stack)) {
- // usuwanie niepotrzebneg zamykajacego
- tmp = w->next;
- w->next = w->next->next;
- free(tmp);
- } else {
- pop(&stack);
- }
- }
- }
- w = w->next;
- }
- // usuwanie nadmiarowych nawasow otwierajacych
- while (!is_empty(stack)) {
- w = pop(&stack);
- tmp = w->next;
- w->next = w->next->next;
- free(tmp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement