M
Maurice
how could you pass the head from a linked list class so that it could be
used in a main file?
here is the content of the linkedlist.h file:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
//******************************************************************
// SPECIFICATION FILE (linkedlist.h)
// This file gives the specification of a dynamic linked list representation
of
// a linked list.
// The list nodes are maintained in ascending order of value
// The private data members:
// head pointer to the first node in the list
// if the list is empty, node is set to NULL
// currentsize the number of integers currently in the list
//******************************************************************
struct node { // structure of node of list
int item; // integer in the list
node* link; // link to next node in list
};
class linkedlist
{
public:
linkedlist(); //Constructor
// Precondition
// Postcondition
// List is empty, head is set to NULL
void Print();
// Postcondition:
// All node values (if any) in list have been printed
void Insert( /* in */ int item );
// Precondition:
// item is value to add to list
// Postcondition:
// item is in list
// && List nodes are in ascending order
void Delete( /* in */ int item );
// Precondition:
// item is value to delete from list
// Postcondition:
// item deleted from the list
// && List nodes are in ascending order
int linkedlist::Size();
// Postcondition:
// number of nodes (items) in the list is returned
linkedlist::~linkedlist(); // Destructor
// Precondition:
// Link list created by constructor
// (may be empty)
// Postcondition:
// Storage for any nodes on the list freed
void senddata(node* head);
private:
int currentsize; // current number of items in list
// start of linked list
node* head;
};
#endif
used in a main file?
here is the content of the linkedlist.h file:
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
//******************************************************************
// SPECIFICATION FILE (linkedlist.h)
// This file gives the specification of a dynamic linked list representation
of
// a linked list.
// The list nodes are maintained in ascending order of value
// The private data members:
// head pointer to the first node in the list
// if the list is empty, node is set to NULL
// currentsize the number of integers currently in the list
//******************************************************************
struct node { // structure of node of list
int item; // integer in the list
node* link; // link to next node in list
};
class linkedlist
{
public:
linkedlist(); //Constructor
// Precondition
// Postcondition
// List is empty, head is set to NULL
void Print();
// Postcondition:
// All node values (if any) in list have been printed
void Insert( /* in */ int item );
// Precondition:
// item is value to add to list
// Postcondition:
// item is in list
// && List nodes are in ascending order
void Delete( /* in */ int item );
// Precondition:
// item is value to delete from list
// Postcondition:
// item deleted from the list
// && List nodes are in ascending order
int linkedlist::Size();
// Postcondition:
// number of nodes (items) in the list is returned
linkedlist::~linkedlist(); // Destructor
// Precondition:
// Link list created by constructor
// (may be empty)
// Postcondition:
// Storage for any nodes on the list freed
void senddata(node* head);
private:
int currentsize; // current number of items in list
// start of linked list
node* head;
};
#endif