Linked List Algorthm
Variables
struct listtype { itemtype  data;   // itemtype can be any data type
                  int next;         // pointer to the location of the next item in the list
                };                  //      some books call it link instead of next

listtype ll[MAXSIZE];

int list;               // Location of the first item in the list
int avail;              // Location of the first empty or available spot in the list, also called free

int p;                  // variable used to tranverse the list during linked list operations
int c;                  // another variable to tranverse the list and keep track of the "current" item
int prev;               // Keep track of the Previous item in the list. The one logically before p

Add

if ( avail == -1)
{
   list is full
   return;
}

p = avail                 // Get location to add the new item
avail = ll[avail].next    // move to the next avail spot.  if avail is -1, no more empty spots

ll[p].data = newitem;     // put the new item in the right spot in the list. Assume the item was read in somewhere

// Find the item in the list previous to the new item we are adding
c= list;                             // start with the first one
prev = -1;
while ( (newitem > ll[c].data) && (c != -1) )
{
    prev = c;                       // we haven't found the spot yet, move to the next item in the list
    c = ll[c].next;
}

if  ( prev != -1)
{                                   // item is in the middle of the list
      ll[p].next  = ll[prev].next
      ll[prev].next = p
} else
{                                   // prev is -1 so it is the first one
      ll[p].next = list
      list = p
}


Print

c  = list               // Set c to the location of the first item in the list
while ( c != -1 )         // if c is -1, must be the end so we stop
{
     cout<<ll[c].data;
     c = ll[c].next;     //move to the next one logically
}

Delete
// Find location of the item in the list and the location of the previous
c= list;                             // start with the first one
prev = -1;
while ( (newitem != ll[c].data) && ( c != -1) )
{
    prev = c;                       // we haven't found the spot yet, move to the next item in the list
    c = ll[c].next;
}

if (c  ==  -1)
{                         // item is not in the list
       return;
}
// now fix the links
if  ( prev != -1)
{                                   // item is in the middle of the list
      ll[prev].next  = ll[p].next
     
} else
{                                   // prev is -1 so it is the first one
      list = ll[p].next
}

// Now add the deleted spot to the availiable list
ll[p].next = avail;
avail = p;