Csci 2010 Lab11 Link Lists Lab 11a Linked Lists Preparation Create Visual Studio C Project Q37198727

CSCI 2010 Lab11 Link-Lists

Lab 11A Linked-Lists

Preparation

  1. Create a Visual Studio C++ Project C2010Lab11A
  2. Add the following to the project.

//LinkedList.cpp

#include
#include “LinkedList.h”
using namespace std;

//—————————————————
//List Element Members
//—————————————————
ListElement::ListElement(int d, ListElement * n)
{
   datum=d;
   next=n;
}
int ListElement::getDatum () const
{
   return datum;
}
ListElement const* ListElement::getNext () const
{
   return next;
}

//—————————————————
//LinkedList Members
//—————————————————
LinkedList::LinkedList ()
{
   head=NULL;
}

void LinkedList::insertItem(int item)
{
   ListElement *currPtr = head;
   ListElement *prevPtr = NULL;
   ListElement *newNodePtr;     //points to a new node

   while(currPtr != NULL && item >currPtr->datum)
   {
       prevPtr = currPtr;
       currPtr = currPtr->next;
   }

   newNodePtr = new ListElement(item, currPtr);

   if (prevPtr == NULL) // insert at thebeginning
       head=newNodePtr;
   else
       prevPtr->next =newNodePtr;
}

void LinkedList::makeList()
{
   int InValue;
   ListElement *currPtr;
   ListElement *newNodePtr;

  

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.