PSEUDOCODE FOR SORTED_LIST INSRT_REC







node* insrt_rec(node* ptr, int key, int& success)  
   node* tmp = ptr
   success = TRUE
   if ptr == NULL OR ptr->item  >=  key 
      if (tmp = new node) != NULL
         tmp->item = key
         tmp->next = ptr
      |  tmp == NULL  
         success = FALSE 
      fi 
   |    ptr != NULL AND ptr->item  <  key) 
      ptr->next = insrt_rec(ptr->next, key, success) 
   fi
   return tmp 
end     insrt_rec



PSEUDOCODE FOR SORTED_LIST INSERT


 
 
int insert(int key) 
   int success
   head = insrt_rec(head, key, success)
   return success 
end    insert



PSEUDOCODE FOR SORTED_LIST DEL_REC
   

node* Del_rec(node* ptr, int key, int& success)  
   node* tmp = ptr
   success = FALSE
   if ptr != NULL  
      if ptr->item == key 
         tmp = ptr->next
         delete ptr
         success = TRUE 

   //    if ptr->item > key,   key is not in the list

      | ptr->item  <  key)   // keep searching 
         ptr->next = Del_rec(ptr->next, key, success) 
      fi

   // else at end of list and item not found 

   fi
   return tmp 
end Del_rec


PSEUDOCODE FOR SORTED_LIST DESTRUCTOR

 
 
$\sim$sorted_list()  
   node *prev, *curr
   if head != NULL  
      prev = head
      do prev->next != NULL  
         curr = prev->next
         delete prev
         prev = curr
      od
      delete prev
      head = NULL
   fi
   // Else there is nothing to do, list already empty 
end    sorted_list




Bernard Waxman
9/12/1997