### 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;
 ``1234567891011121314151617181920212223242526`` ``````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?
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158`` ``````#include using namespace std; class Node { public: Node () {} Node* putOneNode (Node*, double); double getOneNode (); Node* getNextPointer (); void putNextPointer (Node*); private: double nr; Node* nextPtr; }; #include 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.