My Lecturer give me an assignment.. to compile a program using linklist.. but im being frustated to make this program run.. can anybody help me whats wrong with my program..
this is my program code :
// listnode.h
// Template ListNode class definition.
#ifndef LISTNODE_H
#define LISTNODE_H
// forward declaration of class List
template< class NODETYPE > class List;
template< class NODETYPE >
class ListNode {
friend class List< NODETYPE >; // make List a friend
public:
ListNode( const NODETYPE & ); // constructor
NODETYPE getData() const; // return data in node
private:
NODETYPE data; // data
ListNode< NODETYPE > *nextPtr; // next node in list
}; // end class ListNode
// constructor
template< class NODETYPE >
ListNode< NODETYPE >::ListNode( const NODETYPE &info )
: data( info ),
nextPtr( 0 )
{
// empty body
} // end ListNode constructor
// return copy of data in node
template< class NODETYPE >
NODETYPE ListNode< NODETYPE >::getData() const
{
return data;
} // end function getData
#endif
==============
// list.h
// Template List class definition.
#ifndef LIST_H
#define LIST_H
#include <iostream>
using std::cout;
#include <new>
#include "listnode.h" // ListNode class definition
// insert node at front of list
template< class NODETYPE >
void List< NODETYPE >::insertAtFront( const NODETYPE &value )
{
ListNode< NODETYPE > *newPtr = getNewNode( value );
if ( isEmpty() ) // List is empty
firstPtr = lastPtr = newPtr;
else { // List is not empty
newPtr->nextPtr = firstPtr;
firstPtr = newPtr;
} // end else
} // end function insertAtFront
// insert node at back of list
template< class NODETYPE >
void List< NODETYPE >::insertAtBack( const NODETYPE &value )
{
ListNode< NODETYPE > *newPtr = getNewNode( value );
if ( isEmpty() ) // List is empty
firstPtr = lastPtr = newPtr;
else { // List is not empty
lastPtr->nextPtr = newPtr;
lastPtr = newPtr;
} // end else
} // end function insertAtBack
// delete node from front of list
template< class NODETYPE >
bool List< NODETYPE >::removeFromFront( NODETYPE &value )
{
if ( isEmpty() ) // List is empty
return false; // delete unsuccessful
value = tempPtr->data; // data being removed
delete tempPtr;
return true; // delete successful
} // end else
} // end function removeFromFront
// delete node from back of list
template< class NODETYPE >
bool List< NODETYPE >::removeFromBack( NODETYPE &value )
{
if ( isEmpty() )
return false; // delete unsuccessful
// locate second-to-last element
while ( currentPtr->nextPtr != lastPtr )
currentPtr = currentPtr->nextPtr;
lastPtr = currentPtr;
currentPtr->nextPtr = 0;
} // end else
value = tempPtr->data;
delete tempPtr;
return true; // delete successful
} // end else
} // end function removeFromBack
// is List empty?
template< class NODETYPE >
bool List< NODETYPE >::isEmpty() const
{
return firstPtr == 0;
} // end function isEmpty
// return pointer to newly allocated node
template< class NODETYPE >
ListNode< NODETYPE > *List< NODETYPE >::getNewNode(
const NODETYPE &value )
{
return new ListNode< NODETYPE >( value );
} // end function getNewNode
// display contents of List
template< class NODETYPE >
void List< NODETYPE >::print() const
{
if ( isEmpty() ) {
cout << "The list is empty\n\n";
return;
// thelist.cpp
// List class test program.
#include <iostream>
using std::cin;
using std::endl;
#include <string>
using std::string;
#include "list.h" // List class definition
// function to test a List
template< class T >
void testList( List< T > &listObject, const string &typeName )
{
cout << "Testing a List of " << typeName << " values\n";
case 2:
cout << "Enter " << typeName << ": ";
cin >> value;
listObject.insertAtBack( value );
listObject.print();
break;
case 3:
if ( listObject.removeFromFront( value ) )
cout << value << " removed from list\n";
listObject.print();
break;
case 4:
if ( listObject.removeFromBack( value ) )
cout << value << " removed from list\n";
listObject.print();
break;
} // end switch
} while ( choice != 5 ); // end do/while
cout << "End list test\n\n";
} // end function testList
// display program instructions to user
void instructions()
{
cout << "Enter one of the following:\n"
<< " 1 to insert at beginning of list\n"
<< " 2 to insert at end of list\n"
<< " 3 to delete from beginning of list\n"
<< " 4 to delete from end of list\n"
<< " 5 to end list processing\n";
} // end function instructions
int main()
{
// test List of int values
List< int > integerList;
testList( integerList, "integer" );
// test List of double values
List< double > doubleList;
testList( doubleList, "double" );
return 0;
} // end main
please tell me where's the mistake and give me answer how this program suppose to write..
o... and my lecturer ask me to convert the data type to string.. can anybody help me please... T__T
c:\documents and settings\dicky\desktop\contoh1.cpp(57) : fatal error C1083: Cannot open include file: 'listnode.h': No such file or directory
Error executing cl.exe.
here is my error i'm compiling it using microsoft visual c++ 6.0