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

removed element *

parent 47a7cec8
Branches
No related tags found
No related merge requests found
Pipeline #36565 passed
...@@ -294,7 +294,9 @@ typedef struct _element { ...@@ -294,7 +294,9 @@ typedef struct _element {
int data; int data;
struct _element *next; struct _element *next;
} element; } element;
typedef element* stack; typedef struct _stack {
element *top;
} stack;
``` ```
## Fonctionnalités? ## Fonctionnalités?
...@@ -302,12 +304,12 @@ typedef element* stack; ...@@ -302,12 +304,12 @@ typedef element* stack;
. . . . . .
```C ```C
void stack_create(stack *s); // *s = NULL; void stack_create(stack *s); // s->top = 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);
void stack_pop(stack *s, int *val); void stack_pop(stack *s, int *val);
void stack_peek(stack s, int *val); void stack_peek(stack s, int *val);
bool stack_is_empty(stack s); // return NULL == stack; bool stack_is_empty(stack s); // return NULL == s.top;
``` ```
# La liste chaînée et pile (3/6) # La liste chaînée et pile (3/6)
...@@ -335,7 +337,7 @@ void stack_push(stack *s, int val) { ...@@ -335,7 +337,7 @@ void stack_push(stack *s, int val) {
element *elem = malloc(sizeof(*elem)); element *elem = malloc(sizeof(*elem));
elem->data = val; elem->data = val;
elem->next = *s; elem->next = *s;
*s = elem; s->top = elem;
} }
``` ```
...@@ -361,7 +363,7 @@ void stack_push(stack *s, int val) { ...@@ -361,7 +363,7 @@ void stack_push(stack *s, int val) {
```C ```C
void stack_peek(stack s, int *val) { void stack_peek(stack s, int *val) {
*val = s->data; *val = s.top->val;
} }
``` ```
...@@ -388,8 +390,8 @@ void stack_peek(stack s, int *val) { ...@@ -388,8 +390,8 @@ void stack_peek(stack s, int *val) {
```C ```C
void stack_pop(stack *s, int *val) { void stack_pop(stack *s, int *val) {
stack_peek(*s, val); stack_peek(*s, val);
element *tmp = *s; element *tmp = s->top;
*s = (*s)->next; s->top = s->top->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