Commit 2a10535ab03b934ac46d25a4ba02d60986294741

Authored by bjeanlou
1 parent 500d264d

end Lesson 1

Showing 4 changed files with 73 additions and 9 deletions   Show diff stats
1 #include "Slist.h" 1 #include "Slist.h"
  2 +
  3 +List make_empty_list(){
  4 + return NULL;
  5 +}
  6 +
  7 +int is_empty(List l){
  8 + return l==NULL;
  9 +}
  10 +int isIn_List(List l, char e){
  11 + return !is_empty(l) &&
  12 + (isIn_tree(l.letter,e) ||
  13 + isIn_list(l.next,e));
  14 +}
  15 +
  16 +
  17 +//add
  18 +void addHead(List*l,char e){
  19 + cell* tmp=malloc(sizeof(cell));
  20 + tmp->letter=make_tree(e);
  21 + tmp->next=*l;
  22 + *l=tmp;
  23 +}
  24 +void addNext(List*l,char e){
  25 + if(is_empty(*l))
  26 + addHead(l,e);
  27 + else{
  28 + cell* tmp=malloc(sizeof(cell));
  29 + tmp->letter=make_tree(e);
  30 + tmp->next=*l->next;
  31 + *l=tmp;
  32 +}
  33 +void addAlpha(List*l,char e){
  34 + if(is_empty(*l) || e<(l->letter->val)){
  35 + addHead(l,e);
  36 + return;
  37 + }
  38 + cell* crt=*l;
  39 + while(!is_empty(crt->next) && e < crt->next->letter->val)
  40 + crt=crt->next;
  41 + if(is_empty(crt->next))
  42 + addHead(&crt->next,e);
  43 +
  44 + if(e> crt->next-letter->val){
  45 +
  46 +}
@@ -14,9 +14,10 @@ typedef @@ -14,9 +14,10 @@ typedef
14 //function 14 //function
15 List* make_empty_List(); 15 List* make_empty_List();
16 int is_empty(List); 16 int is_empty(List);
17 -tree* head(List);  
18 -List* Queue(List);  
19 - 17 +int isIn_list(List,char);
  18 +void addAlpha(List*,char);
  19 +void addHead(List*,char);
  20 +void addNext(List*,char);
20 21
21 22
22 23
1 #include "tree.h" 1 #include "tree.h"
  2 +
  3 +tree make_empty_tree(){
  4 + return NULL;
  5 +}
  6 +int is_empty(tree t){
  7 + return t==NULL;
  8 +}
  9 +int is_leaf(tree t){
  10 + return is_empty(t.next);//<=>t.val=='\0'
  11 +}
  12 +int is_end(tree t){
  13 + return isIn_list(t.next,'\0');
  14 +}
  15 +
@@ -15,17 +15,21 @@ typedef @@ -15,17 +15,21 @@ typedef
15 15
16 16
17 //functions 17 //functions
18 -tree* make_empty_tree(); 18 +tree make_empty_tree();
  19 +tree make_tree(char);
  20 +int is_empty(tree);
  21 +int is_leaf(tree);
  22 +int is_end(tree);
19 tree* cons_tree(); 23 tree* cons_tree();
20 tree* load_tree(FILE*,tree*); 24 tree* load_tree(FILE*,tree*);
21 -int is_empty(tree);  
22 -char value(tree);  
23 //char*? values(tree); 25 //char*? values(tree);
24 void print_all(tree); 26 void print_all(tree);
25 -int isIn(tree,string);  
26 -  
27 - 27 +int isIn_tree(tree,char);
  28 +int strIsIn_tree(tree,string);
28 29
29 30
  31 +/*
  32 +words end with '\0' and
  33 +*/
30 34
31 #endif //TREE_H 35 #endif //TREE_H