Linked List

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top