ns-allinone-2.35/rap/raplist.cc
void List::SortedInsert(void *item, float sortKey)
{
  ListElement *element = new ListElement(item, sortKey);
  ListElement *ptr;	        // keep track
  
  if (IsEmpty()) 
    {				// List is empty, put in front
      first = element;
      last = element;
    } 
  else if (sortKey < first->key) 
    {				// item goes on front of List	
      element->next = first;
      first = element;
    } 
  else 
    {				// look for first elt in List bigger than item
      for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
	if (sortKey < ptr->next->key) 
	  {
	    element->next = ptr->next;
	    ptr->next = element;
	    return;
	  }	
      }
      last->next = element;	// item goes at end of List
      last = element;
    }
  
  size++;
}
//----------------------------------------------------------------------
// List::SortedInsert
//      Insert an "item" into a List, so that the List elements are
//	sorted in increasing order by "sortKey".
//      
//	Allocate a ListElement to keep track of the item.
//      If the List is empty, then this will be the only element.
//	Otherwise, walk through the List, one element at a time,
//	to find where the new item should be placed.
//
//	"item" is the thing to put on the List, it can be a pointer to 
//		anything.
//	"sortKey" is the priority of the item.
//----------------------------------------------------------------------
:SortedInsert
Insert an "item" into a List, so that the List elements are
sorted in increasing order by "sortKey".

Allocate a ListElement to keep track of the item.
If the List is empty, then this will be the only element.
Otherwise, walk through the List, one element at a time,
to find where the new item should be placed.

"item" is the thing to put on the List, it can be a pointer to
anything.
"sortKey" is the priority of the item.
: SortedInsert Insert an " item " into a List so that the List elements are sorted in increasing order by " sortKey " . Allocate a ListElement to keep track of the item . If the List is empty then this will be the only element . Otherwise walk through the List one element at a time to find where the new item should be placed . " item " is the thing to put on the List it can be a pointer to anything . " sortKey " is the priority of the item .
void List::SortedInsert(void *item, float sortKey)
{
  ListElement *element = new ListElement(item, sortKey);
  ListElement *ptr;	        
  if (IsEmpty()) 
    {				
      first = element;
      last = element;
    } 
  else if (sortKey < first->key) 
    {				
      element->next = first;
      first = element;
    } 
  else 
    {				
      for (ptr = first; ptr->next != NULL; ptr = ptr->next) {
	if (sortKey < ptr->next->key) 
	  {
	    element->next = ptr->next;
	    ptr->next = element;
	    return;
	  }	
      }
      last->next = element;	
      last = element;
    }
  size++;
}
void List :: SortedInsert ( void * item , float sortKey ) { ListElement * element = new ListElement ( item , sortKey ) ; ListElement * ptr ; if ( IsEmpty ( ) ) { first = element ; last = element ; } else if ( sortKey < first -> key ) { element -> next = first ; first = element ; } else { for ( ptr = first ; ptr -> next != NULL ; ptr = ptr -> next ) { if ( sortKey < ptr -> next -> key ) { element -> next = ptr -> next ; ptr -> next = element ; return ; } } last -> next = element ; last = element ; } size ++ ; }
List::SortedInsert
Insert an "item" into a List, so that the List elements are
sorted in increasing order by "sortKey".
List :: SortedInsert Insert an " item " into a List so that the List elements are sorted in increasing order by " sortKey " .
// keep track // List is empty, put in front // item goes on front of List	 // look for first elt in List bigger than item // item goes at end of List