/*
 * Sonny Rajagopalan
 * CISC181-040 (06J), Summer 2006.
 * Linked list header/implementation file (1/many)
 */
#include <iostream>
using namespace std;

struct Node
{
  int key;
  Node* next;
};

struct LinkedList
{
  Node* head;
  Node* tail;
};

// what happens when you remove the "&"
void createANewLinkedList(struct LinkedList& newList)
{
  newList.head=NULL;
  newList.tail=NULL;
}
// could i remove this & without anything bad happening?
void printLinkedList(const struct LinkedList &list)
{
  Node* currentNode=list.head;
  for (; currentNode != NULL; currentNode=currentNode->next)
    {
      cout << "Key is " << currentNode->key << endl;
    }
}

void addToTailOfLinkedList(struct LinkedList &list, int key)
{
  Node* newNode = new Node;
  Node* currentNode = list.head;

  newNode->key = key;
  newNode->next = NULL;

  if (list.head == NULL)
    {
      list.head = newNode;
      list.tail = newNode;
      list.head->next = NULL;
    }
  else
    {
      // identify the funkiness below:
      for (; currentNode->next != NULL; currentNode=currentNode->next);    
      currentNode->next=newNode;

      list.tail = newNode;
    }
}


void deleteAKeyFromLinkedList(struct LinkedList &list, int key);
// assume that the key is unique.

void addToHeadOfLinkedList(struct LinkedList &list, int key);
{
  Node* newNode = new Node;
  Node* currentNode = list.hear;

  newNode->key = key;
  newNode->next = currentNode;

  if (list.head == NULL)
    {
      list.head = newNode;
      list.tail = newNode;
      list.head->next = NULL;
    }
  else
    {
      list.head = newNode;      
    }
}
// assume that the key is unique.

void addBetweenKeysInLinkedList(struct LinkedList &list, int keyLow, int keyHigh);
// assume that the key is unique, and insert between keys keyLow and keyHigh
// Further, assume that linked list is sorted in ascending order.

