Ok, I'm freaking lost... I can't figure out how to get the "location" variable to work. Its a basic program, you input numbers and it HAS to use a recursive function to insert the new node into the list (even tho I could write 2 lines of code) and well I'm just... needing help.
Header
typedef int item;
//typedef digit* ptrType;
class number
{
public:
number(); // constructor
~number(); // deconstructor
// member functions
void number::insert(item* &location, int newValue);
bool isEmpty() const;
int getLength() const;
private:
struct digit
{
item Value; // a digit value, 0-9
digit* location;
struct digit* next;
struct digit* prev;
};
typedef digit* ptrType;
int size;
digit *head;
digit *tail;
digit *curr;
digit *find(int index) const;
};
CLASS
#include <iostream>
#include <cstddef>
#include <new>
#include "number.h"
using namespace std;
number::number() : size(0), head(NULL)
{
}
number::~number()
{
while (!isEmpty())
remove(NULL);
}
bool number::isEmpty() const
{
return size == 0;
}
int number::getLength() const
{
return size;
}
void number::insert(item &location, int newValue)
{
if (location==NULL)
{
head = location;
}
if (location->next == NULL) // end of list
{
location->next = newValue;
break;
}
if (newValue > location->Value) && (newValue < location->next->Value)
{
digit *newPtr = new digit;
newPtr->Value = newValue;
newPtr->next = location->next;
newPtr->prev = location;
location->next->prev = newPtr;
location->next = newPtr;
}
else
{
Insert(location->next, newValue); // general case
}
}
Main (Basic)
#include <iostream>
#include <string>
#include <cmath>
#include "number.h"
using namespace std;
void main()
{
int Entry1 = 1;
int Entry2 = 1;
number N;
digit location;
while (Entry1 != 0)
{
cout << "Enter Numbers to be inserted (0 the end): ";
cin >> Entry1;
N.insert(N.tail, Entry1);
}
}