void LinkedListPriorityQueue::enqueue(string value) {
	newOne = new Entry;
    newOne -> name = value;
    newOne -> next = NULL;
    number++;
    
// Use a recursive function to insert an element in order
    InsertSorted(list, newOne);
}
Ejemplo n.º 2
0
/* Inserts a record with given id in the slow list.
 * This is done by using a binary search through the list and
 * extending the list.
 * Returns pointer to the new record or NULL if memory allocation fails
 *
 */
void *STinsert(
 SEARCH_TABLE *t,  /* read-write table */
 const void *f)   /* key to insert */
{
 void *c;
 t->nrSlowList++;
 c = (void *)ChkRealloc(t->slowList, t->nrSlowList*t->recSize);
 if(c == NULL)
  return NULL;
 t->slowList = c;
 return InsertSorted(f,t->slowList, t->nrSlowList-1,t->recSize,t->cmp);
}
void LinkedListPriorityQueue::InsertSorted(Entry * &list,  Entry *newOne){
    
    //Base case
    
    if(list==NULL || (compareStrings(list -> name, newOne -> name) < 0)){
        
        newOne -> next = list;
        list = newOne;
        
    } else
        InsertSorted(list -> next, newOne);      // Recursive Case
    
}