Hi Guys,

First post on here :) I've been here before and i've usually been able to find what I needed but now I'm in a bit of a bind.

I'm doing a piece of coursework for my university course and i've just hit a huge brick wall. Basically what I have to do is use a Linked List to store strings (Each node stores 1 string). I need a function to add a node, and one to print the contents of the list to the console. The problem is that I have to do it using 3 files. One header and one cpp to declare all the functions etc. and a third test.cpp to write some tests.

I haven't even started the test conditions because all that I keep getting are 3 errors.

1 - 'initialise' was not declared in this scope
2 - 'addNode' was not declared in this scope
3 - 'printContents' was not declared in this scope

All these errors are in the main method. Just incase this may be relevant, I'm using Xcode. I usually use Visual Studio 2010 but I wont have access to it until tomorrow.

Heres the code I have so far for my Dictionary.h file:

#ifndef DICTIONARY_H
#define DICTIONARY_H

#include <iostream>
using namespace std;

class DictionaryTree
{
private:
	
	struct node {
		string x;
		node *next;
	};
	
	node *root;
	node *conductor;
	
	DictionaryTree() { }
	
public:

	void addNode (string word);
	void initialise();
	void printContents();
};

#endif

And here is my Dictionary.cpp:

#include <iostream>
#include "Dictionary.h"

void DictionaryTree::addNode (string word)
{
	conductor->next = new node;  // Creates a node at the end of the list
	conductor = conductor->next; // Points to that node
	conductor->next = 0;         // Prevents it from going any further
	conductor->x = word;
}

void DictionaryTree::initialise()
{
	root = new node;
	root->next = 0; 
	root->x = "";
}

void DictionaryTree::printContents()
{
	conductor = root;
	if ( conductor != 0 ) { 
		while ( conductor->next != 0 ) {
			cout<< conductor->x;
			cout << endl;
			conductor = conductor->next;
		}
		cout<< conductor->x;
		cout << endl;
	}	
}


int main()
{
	initialise();
	addNode("Test1");
	addNode("Test2");
	printContents();
}

Any help would be very appreciated. Im about to put my head through a wall on this one :)

Recommended Answers

All 4 Replies

What exactly is the assignment? Because everything you are trying to code here already exists in the standard template library (STL). More specifically in the list container.

the assignment basically gets us to write a basic Linked list so that we better appreciate the underlying structure. I think I've got it sorted now though. The problem was that I wasn't declaring an instance of the object in the main method. I added DictionaryTree test; as the first line of the main method and then put test. before every function call. Nearly finished the assignment now :)

the assignment basically gets us to write a basic Linked list so that we better appreciate the underlying structure. I think I've got it sorted now though. The problem was that I wasn't declaring an instance of the object in the main method. I added DictionaryTree test; as the first line of the main method and then put test. before every function call. Nearly finished the assignment now :)

If I was you, I would rewrite/redo the assignment in your spare time. This time round though, you research how you would write a linked list so that you can add any object to it, and then move on to a double linked list structure. This is great practice for understanding basic data structures and you will learn a lot of excellent c++ techniques. Or, you could even start with writing your own custom dynamic array "class".

You also need to consider speed when you write custom datastructures. If you haven't already, I suggest you research time complexity and Big-O notation. Try to always think of the speed of any algorithms you write

If I was you, I would rewrite/redo the assignment in your spare time. This time round though, you research how you would write a linked list so that you can add any object to it, and then move on to a double linked list structure. This is great practice for understanding basic data structures and you will learn a lot of excellent c++ techniques. Or, you could even start with writing your own custom dynamic array "class".

You also need to consider speed when you write custom datastructures. If you haven't already, I suggest you research time complexity and Big-O notation. Try to always think of the speed of any algorithms you write

Thanks for the reply. I completely agree. I've studied Big-Oh and timing etc. but this assignment was one of those quick fire, get it done in a few days, type of things. Got everything working now and its ready for submitting.

Thanks for all the help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.