Node sorting

can anyone give me some hints i try to sort the data, but for example, i add 4 and 6. if i add 3 is fine, but i add any numbers bigger than 4 will be omit;
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
Node* Node::putOneNode (Node* x, double d) {
 Node* temp = NULL;
 if (temp = new Node()) {
	temp->nextPtr = x;
	temp->nr = d;
 }
return temp;
}
bool BagList::putNode (double udata) {
 bool x = false;
 Node* temp1;
 Node A;
 Node* temp;
 temp1 = A.putOneNode (ListPointer, udata);
	
for (ListPointer; ListPointer != NULL; ListPointer =  ListPointer->getNextPointer()) {
  if (ListPointer->getOneNode() < udata) {
   // Help Here Thank You
   }
 }
 if (temp1 != NULL) {	
   ListPointer = temp1;
   x = true;
 }
return x;
}
Last edited on
22 posts and no code tags? :(
what is no code tags?
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include <iostream>
using namespace std;

class Node {
public:
	Node () {}
	Node* putOneNode (Node*, double);
	double getOneNode ();
	Node* getNextPointer ();
	void putNextPointer (Node*);
private:
	double nr;
	Node* nextPtr;
};

#include <cstdlib>

Node* Node::getNextPointer (){
	return nextPtr;
}
void Node::putNextPointer (Node* x){
	this->nextPtr = x;
}
Node* Node::putOneNode (Node* x, double d) {
	Node* temp = NULL;
	if (temp = new Node()) {
		temp->nextPtr = x;
		temp->nr = d;
	}
	return temp;
}
double Node::getOneNode() {
	return nr;
}

//#include "BagList.h"
class BagList {
public:
	BagList ();
	bool putNode (double);
	void getList ();
	Node* findNode (double);
	void  deleteNode (double);
private:
	Node* ListPointer;
};


BagList::BagList () 
	{ListPointer = NULL;}
bool BagList::putNode (double udata) {
	bool x = false;
	Node* temp1;
	Node A;
	Node* temp;
	temp1 = A.putOneNode (ListPointer, udata);
	
	for (ListPointer; ListPointer != NULL; ListPointer = ListPointer->getNextPointer()) {
		if (ListPointer->getOneNode() < temp1->getOneNode()) {
			temp = temp1;
			temp1 = ListPointer;
			ListPointer = temp;
		}
	}
	
	if (temp1 != NULL)
	{	ListPointer = temp1;
		x = true;
	}
	return x;
}
Node* BagList::findNode (double udata){
	Node* temp;
	for (temp = ListPointer; temp != NULL && temp->getOneNode() != udata; 
		                    temp = temp->getNextPointer());
	return temp;
}
void BagList::getList() {
	Node* temp;
	for (temp = ListPointer; temp != NULL;
									temp = temp->getNextPointer()) 
		cout << " User Data " << temp->getOneNode () << endl;
}
void BagList::deleteNode (double udata) {
	Node* delPtr = findNode (udata); 
	if (delPtr != NULL) {
		if (ListPointer == delPtr)
			ListPointer = delPtr->getNextPointer();
		else { 	Node* previousPtr; 
			Node* temp = ListPointer; 
			for (previousPtr = NULL; temp != delPtr; 
				previousPtr = temp, temp = temp->getNextPointer());
			previousPtr->putNextPointer(delPtr->getNextPointer());
		}
		delete delPtr;
	}
	else
		cout << "Invalid data entered" << endl;

}

int main () {
    BagList A;
    double udata;
	bool cont = true;
    char sel;
    while (!cin.eof()&&cin.good()&&cont == true) {
	cout << "Enter your function: Add, Delete, Exit, Find, List: ";
	cin >> sel;
	if (!cin.eof()) {
	    switch (sel) {		
		case 'A': case 'a': {
		    cout << "Enter a double-precision number or control-z to end ";
		    cin >> udata;
		    if (!cin.eof() && cin.good())
				cont = A.putNode(udata);
			else
				if (!cin.eof())
					cout << "Invalid data entered" << endl;
		    break;
		}
		case 'D': case 'd': { 
			cout << "Please Enter User Data value to delete: ";
			cin >> udata;
			if (!cin.eof() && cin.good()) 
				A.deleteNode (udata);
			break;
			}
		case 'E': case 'e': {
			cont = false;
			break;
			}
		case 'F': case 'f': {
			cout << "Please Enter User Data value to find: ";
			cin >> udata;
			if (!cin.eof() && cin.good()) 
				if (A.findNode(udata))
					cout << "Node " << udata << " found" << endl;
				else
					cout << "Node " << udata << " not found" << endl; 
			break;
			}
		case 'L': case 'l': {
			cout << "List of nodes" << endl;
			A.getList();
			cout << endl;
			break;
			}
		default: {
			cout << "Invalid function entered." << endl;
			break;
			 }
		   }
	    }
	}
//	system ("PAUSE");
	return 0;
}

Last edited on
[code]--your code goes here--[/code] tags.
Last edited on
Topic archived. No new replies allowed.