Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 14th, 2007, 10:25 AM   #11
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
I don't see where you have changed int to vehicle in the code example. Do you actually understand what is meant by changing the data type of the node ? at current the node class is storing pointer to data of type Integer.

Here is what the modified classes look like now.

#include "vehicle.h"

//forward declaration
class Node;

//class definition
class LinkedList
{
public:
	//construction
	LinkedList();

	//add a new node to the last
	void addToList(Vehicle *data);

	//find an element in list and set current pointer
	void find( int key);

	//get data from element pointed at by current pointer
	Vehicle* getCurrent(void);

	//delete element pointed at by current pointer
	void deleteCurrent(void);

private:
	//data members
	Node *_begin;		//pointer to first element in list
	Node *_end;		//pointer to last element in list
	Node *_current;	//pointer to current element in list
};

class Node
{
public:
	//construction and destruction
	Node();
	~Node();

	//to set and get the next node in the list
	void setNextNode(Node *next);
	Node* getNextNode(void);

	//to set and get the previous node in the list
	void setPrevNode(Node *next);
	Node* getPrevNode(void);

	//to set and access data hold in node
	void setData(Vehicle *data);
	Vehicle* getData(void);

private:
	//data members
	Node *_next;	//pointer to next node in list
	Node *_prev;	//pointer to previous node in list
	Vehicle *_data;	//pointer to data hold in node
};

notice the data variable in the node class is now a pointer of type Vehicle, and that the declarations of the accessor and mutator member functions have been changed to accordingly.

I'll leave you to figure out what needs to be done in the definitions of the linked list and nodes member functions, as I don't want to be doing all your homework for you.
Seif is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
linked list problems bl00dninja C++ 6 Feb 17th, 2008 10:30 AM
dev c++ software, template problem cairo C++ 11 Jun 2nd, 2006 12:42 PM
Singly Linked List Help Firebar Java 3 May 22nd, 2005 10:56 AM
User-defined creatNode and deleteNode functions for a doubly-linked list jgs C 2 Apr 28th, 2005 8:53 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:01 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC