I have this program that is supposed to take in numbers from the Main cpp file and add them to the link list. Eventually i have to sort them then display them on the screen. For right now i am just trying to insert them to the link list but i keep getting a complie error. I am trying to compile this program and i get the following error "'
Node' : no appropriate default constructor available
" Any suggestions ?
I have attached a link to the files in case it is easier for you to view it that way
Project 3
Thanks
Here is my .h file which creates the file currently i am trying to get the Insert Fuction to work so i have the other set as commetns
//---------------------------------------------------------------------------
#ifndef RcrLnkListH
#define RcrLnkListH
//---------------------------------------------------------------------------
typedef int Item;
class List
{
public:
List();// head(0) { };
~List();
bool IsEmpty();
void Show();
bool Insert( Item item );
//{ return Insert( head, item ); }
//bool Delete( Item item );
//{ return Delete( head, item ); }*/
private:
struct Node
{
Item item;
Node *next;
Node( Item itm, Node * nxt )
: item(itm), next(nxt) { }
};
Node * head;
void Show( Node * node );
bool Insert( Node * &node, Item item );
/*bool Delete( Node * & node, Item item );*/
};
//---------------------------------------------------------------------------
#endif
Here is my implemtation file which define the functions in the class:
#include <iostream>
#include <iomanip>
#include <cstdlib>
#pragma hdrstop
#include "RcrLnkListH.h"
using namespace std;
List:: List(): head(0) { };
List:: ~List()
{
}
bool List:: IsEmpty()
{
return head ==0;
}
void List:: Show()
{
void Show( Node * node );
}
void List::Show(Node *node)
{
if (node != NULL)
cout<<node->item;
Show(node->next);
}
bool List:: Insert( Item item )
{
bool Insert( Node * &node, Item item );
return Insert( head, item ); }
bool List:: Insert( Node * &node, Item item )
{
if ((node == NULL) || (item < node->item))
{
Node *newPtr = new Node ;
if (newPtr == NULL)
{}
else
{
newPtr->item = item;
newPtr->next = node;
node = newPtr;
}
}
else Insert(node->next, item);
return Insert( head, item );
}
/*bool Delete(Node * & node, Item item)
{ return Delete( head, item ); }*/
Finally here is my Main CPP file
//---------------------------------------------------------------------------
#include <iostream>
#pragma hdrstop
#include "RcrLnkListH.h"
using namespace std;
//---------------------------------------------------------------------------
int main(int argc, char* argv[])
{
List list;
if (list.IsEmpty == 0)
{
cout<<"not";
}
else
cout<<"is empty";
list.Show();
list.Insert(3);
//list.Insert(1);
//list.Insert(2);
//list.Insert(5);
// list.Insert(4);
list.Show();
// list.Delete(3); list.Show();
// list.Delete(1); list.Show();
// list.Delete(5); list.Show();*/
cin.get();
return 0;
}
//---------------------------------------------------------------------------