4 Replies - 1640 Views - Last Post: 30 July 2007 - 06:41 AM Rate Topic: -----

#1 keystroke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 07

Linked List of data type "Wordy"

Post icon  Posted 29 July 2007 - 08:48 AM

Hi,

Any ideas how to create a Linked List with data type "Wordy"? Wordy is a separate class of it's own with data type char*. Here's a minimal header file for List.


class List
{
private:
	List(const List &);
	const List & Operator = (const List &);
public:
	List(void);
	~List(void);
	void insert(const int);
	void print (ostream&)const;
	friend ostream & operator <<
			   (ostream & ost, const List & l)
   {
		l.print(ost);
		return ost;
   }

private:
	class Node
	{
		  public:
			  int data;
			  Node * next;
			  Node(int d = 0, Node * n = NULL)
					 :data(d), next(n){;;;}
	};
   
	Node head;
	Node trav(const int, const Node * &)const;
	Node * trav(const int, Node * &);
};




That is the original header file for List from my instructor. It works fine for int data type. It inserts and prints ints. But how would I change List to run under data type "Wordy" instead of int. Wordy is from a different header file. I've tried several implementations, and realized I had no clue. Thanks

This post has been edited by keystroke: 29 July 2007 - 08:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Linked List of data type "Wordy"

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Linked List of data type "Wordy"

Posted 29 July 2007 - 02:35 PM

Quote

Any ideas how to create a Linked List with data type "Wordy"? Wordy is a separate class of it's own with data type char*. Here's a minimal header file for List.

first you say data type Wordy then you say class Wordy. I think there is a difference there. If it's a class then you need to create an object that can get the char* thing. If it is a data type (in my understanding) then you need to define a structure where there will be a variable of type char*.

This post has been edited by PennyBoki: 29 July 2007 - 03:16 PM

Was This Post Helpful? 0
  • +
  • -

#3 keystroke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 07

Re: Linked List of data type "Wordy"

Posted 29 July 2007 - 06:04 PM

It's a Linked List with data type Wordy. Wordy happens to be a class of it's own with data type char* thingy. When looking at the code, try imagining the 'int data' part changing into a 'Wordy data'. That way, the List is type Wordy.
Was This Post Helpful? 0
  • +
  • -

#4 Xing  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: Linked List of data type "Wordy"

Posted 29 July 2007 - 06:47 PM

Either templatise the list class or replace every occurrence of int with Wordy. Make sure you include header file which contains definition of Wordy,
Was This Post Helpful? 0
  • +
  • -

#5 keystroke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 07

Re: Linked List of data type "Wordy"

Posted 30 July 2007 - 06:41 AM

Works now, Thanks for your help!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1