Blame view

Slist.c 818 Bytes
500d264d   bjeanlou   create tree ch Sl...
1
  #include "Slist.h"
2a10535a   bjeanlou   end Lesson 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  
  List make_empty_list(){
    return NULL;
  }
  
  int is_empty(List l){
    return l==NULL;
  }
  int isIn_List(List l, char e){
    return !is_empty(l) &&
      (isIn_tree(l.letter,e) ||
       isIn_list(l.next,e));
  }
  
  
  //add
  void addHead(List*l,char e){
    cell* tmp=malloc(sizeof(cell));
    tmp->letter=make_tree(e);
    tmp->next=*l;
    *l=tmp;
  }
  void addNext(List*l,char e){
    if(is_empty(*l))
      addHead(l,e);
    else{
      cell* tmp=malloc(sizeof(cell));
      tmp->letter=make_tree(e);
      tmp->next=*l->next;
      *l=tmp;
  }
  void addAlpha(List*l,char e){
    if(is_empty(*l) || e<(l->letter->val)){
      addHead(l,e);
      return;
    }
    cell* crt=*l;
    while(!is_empty(crt->next) && e < crt->next->letter->val)
      crt=crt->next;
    if(is_empty(crt->next))
      addHead(&crt->next,e);
  
    if(e> crt->next-letter->val){
      
  }