Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prog_C
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
thibault.chatillo
Prog_C
Commits
e5d98251
Commit
e5d98251
authored
4 years ago
by
thib
Browse files
Options
Downloads
Patches
Plain Diff
aled
parent
7822da87
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
calculator/calc.c
+7
-7
7 additions, 7 deletions
calculator/calc.c
calculator/main.c
+4
-14
4 additions, 14 deletions
calculator/main.c
calculator/test.c
+34
-0
34 additions, 0 deletions
calculator/test.c
with
45 additions
and
21 deletions
calculator/calc.c
+
7
−
7
View file @
e5d98251
...
...
@@ -9,6 +9,12 @@
// } stack;
void
stack_init
(
stack
*
stack
,
int
size
,
int
typeSize
)
{
stack
->
data
=
malloc
(
typeSize
*
size
);
stack
->
top
=
-
1
;
stack
->
capacity
=
size
;
}
bool
is_empty
(
stack
stack
)
{
return
stack
.
top
==
-
1
;
}
bool
is_full
(
stack
stack
)
{
return
stack
.
capacity
-
1
==
stack
.
top
;
}
...
...
@@ -22,12 +28,6 @@ void *peek(stack stack) {
int
stack_count
(
stack
stack
)
{
return
stack
.
top
+
1
;
}
void
stack_init
(
stack
*
stack
,
int
size
,
int
typeSize
)
{
stack
->
data
=
malloc
(
typeSize
*
size
);
stack
->
top
=
-
1
;
stack
->
capacity
=
size
;
}
void
stack_destroy
(
stack
*
stack
)
{
free
(
stack
->
data
);
stack
->
top
=
-
1
;
...
...
@@ -68,7 +68,7 @@ char *toPostfix(char *infix, int len) {
char
*
postfix
=
malloc
(
sizeof
(
char
)
*
len
);
int
j
=
0
;
stack_init
(
&
s
,
len
,
sizeof
(
char
));
stack_init
(
&
s
,
len
,
sizeof
(
char
*
));
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
if
(
infix
[
i
]
==
')'
)
{
...
...
This diff is collapsed.
Click to expand it.
calculator/main.c
+
4
−
14
View file @
e5d98251
...
...
@@ -3,19 +3,9 @@
#include
<string.h>
int
main
()
{
// stack s;
// stack_init(&s, 5, sizeof(int));
// int *a = malloc(sizeof(int));
// *a = 3;
// push(&s, a);
// printf("%d \n", *(int *)peek(s));
// stack_destroy(&s);
// free(a);
char
infix1
[]
=
"A+(B/C–D^E"
;
int
len
=
strlen
(
infix1
);
printf
(
"%d
\n
"
,
len
);
//char infix[5]={'a','+','b','x','c'};
char
*
postfix
=
toPostfix
(
infix1
,
len
);
int
len
=
5
;
char
infix
[
5
]
=
{
'a'
,
'+'
,
'b'
,
'x'
,
'c'
};
char
*
postfix
=
toPostfix
(
infix
,
len
);
for
(
int
i
=
0
;
i
<
len
;
i
++
){
printf
(
"%c "
,
postfix
[
i
]);
...
...
@@ -23,7 +13,7 @@ for(int i=0;i<len;i++){
printf
(
"
\n
"
);
free
(
postfix
);
// char *postfix1 = malloc(sizeof(char) * 5);
//
// char *postfix1 = malloc(sizeof(char) * 5);
// stack s;
// int j = 0;
...
...
This diff is collapsed.
Click to expand it.
calculator/test.c
+
34
−
0
View file @
e5d98251
...
...
@@ -5,6 +5,40 @@
int
main
(){
stack
s
;
// stack_init(&s,1,sizeof(int*));
// int x=3;
// push(&s,&x);
// printf("%d",*(int*)pop(&s));
stack
s2
;
stack_init
(
&
s2
,
1
,
sizeof
(
char
*
));
char
c
=
'a'
;
push
(
&
s2
,
&
c
);
printf
(
"%c"
,
*
(
char
*
)
pop
(
&
s2
));
stack_init
(
&
s
,
5
,
sizeof
(
int
*
));
//char infix[5]={'a','+','b','x','c'};
char
infix
[
5
]
=
{
1
,
2
,
3
,
4
,
5
};
for
(
int
i
=
0
;
i
<
5
;
i
++
){
// char *c=malloc(sizeof(char));
// *c=infix[i];
push
(
&
s
,
&
infix
[
5
]);
}
printf
(
"%d"
,
*
(
int
*
)
pop
(
&
s
));
//char z=*(char*)pop(&s);
for
(
int
i
=
0
;
i
<
5
;
i
++
){
// char *c=malloc(sizeof(char));
// *c=infix[i];
// printf("%c\n\n\n\n ",*(char*)pop(&s));
//printf("%c",*(char*)pop(&s));
}
stack_destroy
(
&
s
);
stack_destroy
(
&
s2
);
//free(c);
return
EXIT_SUCCESS
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment