Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
William Sha
ai01_tp1
Commits
793ff086
Commit
793ff086
authored
Nov 24, 2017
by
William Sha
Browse files
Sort debugged
And removed some function logs.
parent
5ca138d0
Changes
3
Hide whitespace changes
Inline
Side-by-side
ai01_tp1.docx
View file @
793ff086
No preview for this file type
main.c
View file @
793ff086
...
...
@@ -51,15 +51,15 @@ int main()
break
;
case
TOKEN_ADD_NB_SPC
:
printf
(
"
what
element do you want to add? "
);
printf
(
"
Which
element do you want to add? "
);
scanf
(
"%s"
,
str_number
);
printf
(
"
\n
At what
position do you want to add it? "
);
printf
(
"
\n
Which
position do you want to add it
at
? "
);
scanf
(
"%d"
,
&
p
);
insert_after_position
(
&
default_list
,
str_number
,
p
);
break
;
case
TOKEN_DEL_NB_SPC
:
printf
(
"
what
element do you want to remove?
\n
"
);
printf
(
"
Which
element do you want to remove?
(please write the position)
\n
"
);
scanf
(
"%d"
,
&
p
);
remove_element
(
default_list
,
p
);
break
;
...
...
tp3.c
View file @
793ff086
...
...
@@ -3,13 +3,6 @@
#include <string.h>
#include "tp3.h"
/**
* A brief description. A more elaborate description
* @param type sometype a type argument.
* @return The test results
*/
void
initialize
(
List
**
list
){
*
list
=
malloc
(
sizeof
(
List
));
(
*
list
)
->
head
=
NULL
;
...
...
@@ -56,9 +49,6 @@ void insert_empty_list(List** list, char* str){
e_vide
->
next
=
NULL
;
(
*
list
)
->
tail
->
next
=
e_vide
;
(
*
list
)
->
tail
=
e_vide
;
//tail doit pointer sur le dernier element
if
(
DEBUG
)
printf
(
"Data inserted : %s
\n
"
,
(
*
list
)
->
head
->
data
);
}
void
insert_beginning_list
(
List
**
list
,
char
*
str
){
...
...
@@ -155,13 +145,13 @@ int remove_element(List* list, int p){
e sera utilisé pour pointer la bonne position, suppr sera utilisé pour "manger le nombre" (désallocation)
*/
while
(
n
<
=
p
){
// tant que l'on est pas arrivé au Pème chiffre
while
(
n
<
p
){
// tant que l'on est pas arrivé au Pème chiffre
do
{
e
=
e
->
next
;
}
while
(
e
->
data
!=
NULL
);
// on parcoure la liste jusqu'au prochain nombre
suppr
=
e
->
next
;
n
++
;
}
suppr
=
e
->
next
;
/* à ce niveau, on en est là :
P
...
...
@@ -205,26 +195,22 @@ int remove_element(List* list, int p){
}
int
compare
(
char
*
str1
,
char
*
str2
){
if
(
!
str1
||
(
strlen
(
str1
)
<
strlen
(
str2
)))
return
2
;
if
(
!
str2
||
(
strlen
(
str1
)
>
strlen
(
str2
)))
return
1
;
int
length
=
strlen
(
str1
);
char
car1
=
*
str1
,
car2
=
*
str2
;
int
int1
=
0
,
int2
=
0
,
i
=
0
;
while
(
i
<
length
){
// O(min(strlen(str1), strlen(str2)))
int1
=
int1
*
10
+
car1
-
'0'
;
int2
=
int2
*
10
+
car2
-
'0'
;
i
++
;
car1
=
*
(
str1
+
i
);
car2
=
*
(
str2
+
i
);
if
(
strlen
(
str1
)
>
strlen
(
str2
)){
return
1
;
}
// calcul des termes convertis en int
if
(
int1
>=
int2
)
if
(
strlen
(
str1
)
<
strlen
(
str2
)){
return
2
;
}
if
(
*
str1
==
'\0'
&&
*
str2
==
'\0'
){
return
2
;
}
if
(
*
str1
<
*
str2
){
return
2
;
}
if
(
*
str1
>
*
str2
){
return
1
;
return
2
;
}
return
compare
(
str1
+
1
,
str2
+
1
);
}
int
sort
(
List
*
list
){
// tri à bulles
...
...
@@ -262,7 +248,7 @@ int sort(List* list){ // tri à bulles
sh
=
ft
->
next
->
next
;
st
=
sh
;
while
(
st
->
next
->
data
!=
NULL
){
st
=
s
h
->
next
;
st
=
s
t
->
next
;
}
for
(
read
=
fh
;
read
!=
ft
->
next
;
read
=
read
->
next
){
// on lit la première valeur
n1
=
strcat
(
n1
,
read
->
data
);
// concatenation
...
...
@@ -270,7 +256,7 @@ int sort(List* list){ // tri à bulles
for
(
read
=
sh
;
read
!=
st
->
next
;
read
=
read
->
next
){
// on lit la première valeur
n2
=
strcat
(
n2
,
read
->
data
);
// concatenation
}
if
(
DEBUG
)
printf
(
"Comparing
...
\n
"
);
if
(
DEBUG
)
printf
(
"Comparing
%s and %s...
\n
"
,
n1
,
n2
);
if
(
compare
(
n1
,
n2
)
==
1
){
ox
=
st
->
next
;
st
->
next
=
ft
->
next
;
...
...
@@ -314,7 +300,6 @@ int sort(List* list){ // tri à bulles
if
(
ft
->
next
->
next
==
sh
){
// le pointeur interval est sur le deuxième nombre donc on a trié tout le reste après
interval
=
list
->
head
;
}
display
(
list
);
}
free
(
n1
);
free
(
n2
);
...
...
@@ -347,19 +332,16 @@ void destruct(List** list){
}
while
((
*
list
)
->
head
->
next
!=
NULL
){
/*cetait pas la bonne condition*/
printf
(
"while
\n
"
);
Element
*
e
=
(
*
list
)
->
head
;
printf
(
"pointe
u
rs : list head : %p, e : %p
\n
"
,
(
*
list
)
->
head
,
e
);
printf
(
"pointers
bf
: list head : %p, e : %p
\n
"
,
(
*
list
)
->
head
,
e
);
if
((
*
list
)
->
head
!=
(
*
list
)
->
tail
){
printf
(
"if
\n
"
);
(
*
list
)
->
head
=
(
*
list
)
->
head
->
next
;
}
printf
(
"free
\n
"
);
printf
(
"pointe
u
rs : list head : %p, e : %p
\n
"
,
(
*
list
)
->
head
,
e
);
printf
(
"pointers
af
: list head : %p, e : %p
\n
"
,
(
*
list
)
->
head
,
e
);
free
(
e
->
data
);
printf
(
"free2
\n
"
);
free
(
e
);
printf
(
"free3
\n
"
);
}
free
(
*
list
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment