Skip to content
Snippets Groups Projects
Verified Commit 013653ff authored by orestis.malaspin's avatar orestis.malaspin
Browse files

corrected slide 42,

parent 3be27c71
Branches
Tags
No related merge requests found
...@@ -439,7 +439,8 @@ char *infix_to_postfix(char* infix) { // init and alloc stack and postfix ...@@ -439,7 +439,8 @@ char *infix_to_postfix(char* infix) { // init and alloc stack and postfix
for (size_t i = 0; i < strlen(infix); ++i) { for (size_t i = 0; i < strlen(infix); ++i) {
if (is_operand(infix[i])) { if (is_operand(infix[i])) {
// we just add operands in the new postfix string // we just add operands in the new postfix string
} else if (infix[i] == '(') { // we push opening parenthesis into the stack } else if (infix[i] == '(') {
// we push opening parenthesis into the stack
stack_push(&s, infix[i]); stack_push(&s, infix[i]);
} else if (infix[i] == ')') { } else if (infix[i] == ')') {
// we pop everything into the postfix // we pop everything into the postfix
...@@ -537,8 +538,8 @@ typedef element* stack; ...@@ -537,8 +538,8 @@ typedef element* stack;
stack stack_create(); // return NULL; stack stack_create(); // return NULL;
void stack_destroy(stack *s); void stack_destroy(stack *s);
void stack_push(stack *s, int val); void stack_push(stack *s, int val);
int stack_pop(stack *s); void stack_pop(stack *s, int *val);
int stack_peek(stack s); void stack_peek(stack s, int *val);
bool stack_is_empty(stack s); // reutrn NULL == stack; bool stack_is_empty(stack s); // reutrn NULL == stack;
``` ```
...@@ -592,8 +593,8 @@ void stack_push(stack *s, int val) { ...@@ -592,8 +593,8 @@ void stack_push(stack *s, int val) {
. . . . . .
```C ```C
int stack_peek(stack s) { void stack_peek(stack s, int *val) {
return s->data; *val = s->data;
} }
``` ```
...@@ -618,8 +619,8 @@ int stack_peek(stack s) { ...@@ -618,8 +619,8 @@ int stack_peek(stack s) {
. . . . . .
```C ```C
int stack_pop(stack *s) { void stack_pop(stack *s, int *val) {
int val = stack_peek(*s); stack_peek(*s, val);
element *tmp = *s; element *tmp = *s;
*s = (*s)->next; *s = (*s)->next;
free(tmp); free(tmp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment