struct name not defined

Hi, while i was doing an assignment for class to write a skip list i get a error telling me the struct Node isnt defined at one function while it works fine for other ones.

i been looking at it for quite a few days already but i cant figure out whats wrong.
hope someone could point me to the right direction

heres the code

skiplist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef SKIPLIST_H_
#define SKIPLIST_H_

#include "LinkedList.cpp"
#include "LinkedList.h"
#include <string>
using namespace std;

class SkipList {
private:
	int compare(string a, string b);
	struct Node {
		string val;
		int occurences ;
		Node** level;
	};
	Node *head, *tail;
public:
	SkipList();
	void add(string s);
	Node* find(string s);
	string getFirst();
	void removeFirst();
	virtual ~SkipList();
};

#endif /* SKIPLIST_H_ */ 



and heres the cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "SkipList.h"
#include <stdlib.h>
using namespace std;


SkipList::SkipList() {
	head = new Node;
	head->level = new Node*[16];
	tail = new Node;
	tail->level = new Node*[16];
	for(int i =0; i<16;i++) {
		head->level[i] = tail;
		tail->level[i] = NULL;
	}
}

void SkipList::add(string s){
	Node* found = find(s);
	if(found != NULL){						//if the value is found increment the occurence
		found->occurences++;
	}else									// if its not found create a new node with the value and place it into the list
	{
		srand(time(NULL));
		int lvl = rand()%16;
		Node *temp = new Node;
		temp->level = new Node*[lvl];
		temp ->occurences = 1;
		temp->val = s;
		Node* start = head;

		for(int i = 15; i >=0;i--){							// decrement start from the highest level
				while(start->level[i] != NULL && compare(s, start->level[i]->val) >= 0){  // loop until reach the end of the level or the value of the next
					if(start->level[i]->val == s) start->level[i]->occurences++;							// 	node is greater than the current s
					else {

					}
				}
			}
	}
}
/**
 * find and return the node containing string
 * if no node is found return NULL
 */
Node* SkipList::find(string s){
	Node* start = head;
	Node* temp = NULL;
	for(int i = 15; i >=0;i--){							// decrement start from the highest level
		while(start->level[i] != NULL && compare(s, start->level[i]->val) >= 0){  // loop until reach the end of the level or the value of the next
			if(start->level[i]->val == s) temp = start->level[i]->val;	// 	node is greater than the current s
			else start = start->level[i];
		}
	}
	return temp;
}
string SkipList::getFirst(){
	return head->level[0]->val;
}
void SkipList::removeFirst(){
	Node* temp = head->level[0];

	int nextlength = sizeof(head->level)/sizeof(head->level[0]);
	for (int i = 0; i < 16; i ++){
		if ( i < nextlength){
			head->level[i] = temp->level[i];
		}
	}
	delete temp;
}

/**
 * compare 2 strings a and b
 * return 1 if a > b
 * return -1 if a < b
 * return 0 if a == b
 */
int SkipList::compare(string a, string b){
	if (a == b) return 0;
	for(int i =0; i < min(a.length(),b.length()); i ++){
		if(a[i] > b[i]) return 1;
		if(a[i] < b[i]) return -1;
	}
	if(a.length()>b.length()) return 1;
	else if(b.length()>a.length()) return -1;
}
SkipList::~SkipList() {
	// TODO Auto-generated destructor stub
}


the error occurs at the find method

this is the exact error message
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oSkipList.o ../SkipList.cpp
../SkipList.cpp:52:1: error: ‘Node’ does not name a type
../SkipList.cpp: In member function ‘int SkipList::compare(std::string, std::string)’:
../SkipList.cpp:86:45: warning: comparison between signed and unsigned integer expressions
../SkipList.cpp:92:1: warning: control reaches end of non-void function
Build error occurred, build is stopped
When you write down the return type, you're still not inside the namespace of the SkipList class.
1
2
3
4
//outside      |inside
Node* SkipList::find(string s){
    //Thus, it's okay to do this, but not the above.
    Node* start = head;
Use 'SkipList::Node *' for the return type.

By the way, you may be missing one case in compare(). When a and b are of the same length, but not equal.
Topic archived. No new replies allowed.