User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,858 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,593 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

Using a class to add/delete/show numbers in a Link List

Join Date: Feb 2005
Posts: 4
Reputation: xsxixtxhx is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xsxixtxhx xsxixtxhx is offline Offline
Newbie Poster

Using a class to add/delete/show numbers in a Link List

  #1  
Apr 1st, 2005
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 "'[HTML]Node' : no appropriate default constructor available[/HTML]" 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;
}
//---------------------------------------------------------------------------
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 6:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC