Advertisement
ankhe

13_a_3

Jan 31st, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. // Zadanie 13 A 3
  2. // szczegolowy szkic
  3.  
  4. // T(n) = Theta(n)
  5. // M(n) = O(n)
  6.  
  7. void popraw(lista* l) {
  8.     lista* a;
  9.     lista* stack = empty();
  10.     lista* w;
  11.     lista* tmp;
  12.     a->next = l;
  13.     w = a;
  14.     while (w) {
  15.         if (w->next) {
  16.             if (w->next->value == '(') {
  17.                 push(&stack, w);
  18.             } else {
  19.                 if (is_empty(stack)) {
  20.                     // usuwanie niepotrzebneg zamykajacego
  21.                     tmp = w->next;
  22.                     w->next = w->next->next;
  23.                     free(tmp);
  24.                 } else {
  25.                     pop(&stack);
  26.                 }
  27.             }
  28.         }
  29.         w = w->next;
  30.     }
  31.  
  32.     // usuwanie nadmiarowych nawasow otwierajacych
  33.     while (!is_empty(stack)) {
  34.         w = pop(&stack);
  35.         tmp = w->next;
  36.         w->next = w->next->next;
  37.         free(tmp);
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement