Skip to content

Commit

Permalink
TP10
Browse files Browse the repository at this point in the history
  • Loading branch information
cfouche3005 committed Mar 28, 2022
1 parent 10ced22 commit ebf1966
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ project(ISENAlgoC C)
set(CMAKE_C_STANDARD 11)

add_executable(ISENAlgoC
TP10/ex1/list.c TP10/ex1/stackList.c TP10/ex1/main.c)
TP10/ex1/stackArray.c TP10/ex1/main.c)
7 changes: 2 additions & 5 deletions TP10/ex1/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>

#include "stackList.h"
#include "stackArray.h"
int main() {
struct Stack* testStack;
//1--------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -48,10 +48,7 @@ int main() {
push(testStack, 69, &valid);
push(testStack, 100, &valid);
push(testStack, 69, &valid);
push(testStack, 100, &valid);
push(testStack, 69, &valid);
push(testStack, 100, &valid);
push(testStack, 69, &valid);

push(testStack, 100, &valid);
push(testStack, 69, &valid);
push(testStack, 63636, &valid);
Expand Down
16 changes: 9 additions & 7 deletions TP10/ex1/stackArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ int top(struct Stack* s, bool* valid) {
*valid = false;
} else {
*valid = true;
return s->elems[stackSize(s) - 1];
return s->elems[s->size-1];
}
}

int pop(struct Stack* s, bool* valid){
top(s,valid);
s-> elems[stackSize(s) - 1] = 0;
s-> size--;
int result = top(s,valid);
s-> elems[s->size-1] = 0;
s-> size= s-> size -1;
return result;
}

unsigned int stackSize(struct Stack* s){
Expand All @@ -46,17 +47,18 @@ bool isStackEmpty(struct Stack* s){
}

void printStack(struct Stack* s) {
if (isStackEmpty(s) == 1) {
if (isStackEmpty(s) == 1 ) {
printf("NULL <– top");
}
else{
printf("%d <– top\n",s->elems[0]);
for (int i = 1; i < stackSize(s); i++){
printf("%d <– top\n",s->elems[s->size-1]);
for (int i = stackSize(s)-2; i >= 0; i--){
printf("%d\n",s->elems[i]);
}
}
}

void deleteStack(struct Stack** s){
free(*s);
*s = NULL;
}

0 comments on commit ebf1966

Please sign in to comment.