Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Test 25 janvier prog seq
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Programmation sequentielle
Test 25 janvier prog seq
Commits
394c1de5
Commit
394c1de5
authored
3 years ago
by
narindra.rajohnso
Browse files
Options
Downloads
Patches
Plain Diff
Fin exercices
parent
ff4a61ff
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex3/ex3.c
+107
-2
107 additions, 2 deletions
ex3/ex3.c
with
107 additions
and
2 deletions
ex3/ex3.c
+
107
−
2
View file @
394c1de5
#include
"stdio.h"
#include
"stdlib.h"
#include
<stdbool.h>
typedef
struct
element
{
int
data
;
struct
element
*
next
;
}
element
;
int
main
(){
typedef
element
*
stack
;
stack
stack_push
(
stack
*
s
,
int
value
)
{
element
*
e
=
malloc
(
sizeof
(
*
e
));
e
->
data
=
value
;
e
->
next
=
NULL
;
e
->
next
=
*
s
;
*
s
=
e
;
return
*
s
;
}
bool
stack_is_empty
(
stack
s
)
{
return
(
s
==
NULL
);
}
stack
stack_peek
(
stack
s
,
int
*
value
)
{
// assert(!stack_is_empty(s));
if
(
stack_is_empty
(
s
))
{
return
NULL
;
}
*
value
=
s
->
data
;
return
s
;
}
stack
stack_pop
(
stack
s
,
int
*
value
)
{
if
(
stack_peek
(
s
,
value
)
==
NULL
)
{
return
NULL
;
}
element
*
tmp
=
s
;
s
=
s
->
next
;
free
(
tmp
);
return
s
;
}
stack
stack_destroy
(
stack
s
)
{
int
value
;
while
(
!
stack_is_empty
(
s
))
{
s
=
stack_pop
(
s
,
&
value
);
}
return
s
;
}
int
peek
(
stack
*
s
,
int
position
)
{
stack
test
;
element
*
it
=
*
s
;
int
count
=
0
;
if
(
position
==
0
)
{
int
value
;
test
=
stack_peek
(
*
s
,
&
value
);
return
value
;
}
while
(
count
!=
position
)
{
it
=
it
->
next
;
count
++
;
}
return
it
->
data
;
}
void
insert
(
stack
*
s
,
int
position
,
int
value
)
{
element
*
it
=
*
s
;
element
*
tmp
=
it
;
int
count
=
0
;
if
(
position
==
0
)
{
*
s
=
stack_push
(
s
,
value
);
return
;
}
while
(
count
!=
position
)
{
tmp
=
it
;
it
=
it
->
next
;
count
++
;
}
element
*
e
=
malloc
(
sizeof
(
*
e
));
e
->
data
=
value
;
tmp
->
next
=
e
;
e
->
next
=
it
;
}
void
printList
(
stack
head
)
{
while
(
head
!=
NULL
)
{
printf
(
"%d "
,
head
->
data
);
head
=
head
->
next
;
}
printf
(
"
\n
"
);
}
void
recurs
(
stack
*
liste
,
stack
*
listePrec
,
int
nbLigne
,
int
*
i
)
{
if
(
*
i
<
nbLigne
)
{
*
liste
=
stack_push
(
liste
,
peek
(
liste
,
*
i
));
(
*
i
)
++
;
}
}
int
main
()
{
int
numLigne
;
scanf
(
"%d"
,
&
numLigne
);
stack
listActuel
=
NULL
;
stack
listPrecedent
;
listActuel
=
stack_push
(
&
listActuel
,
1
);
int
i
=
0
;
recurs
(
&
listActuel
,
&
listPrecedent
,
numLigne
,
&
i
);
printList
(
listActuel
);
stack_destroy
(
listActuel
);
}
\ 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