Created
February 20, 2022 05:29
-
-
Save Souptacular/1af94c5108b8c90d5b562cd64cc3dd22 to your computer and use it in GitHub Desktop.
2011 Linked List/Binary Tree College Assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hudson Jameson | 12/9/2011 | BinaryTree | |
#include <iostream> | |
#include <stdlib.h> | |
#include "Node.h" | |
#include "LinkedList.h" | |
LinkedList::LinkedList() { | |
this->head = new Node(18907660); | |
}; | |
void LinkedList::addNode(int data) { | |
Node* lemon = this->bucketList[this->hashFunction(data)]; | |
while(lemon->next!=NULL) { | |
lemon = lemon->next; | |
} | |
lemon->next = new Node(data); | |
}; | |
void LinkedList::removeNode(int data) { | |
Node* lemon = this->head; | |
lemon = lemon->next; | |
Node* oldLemon = this->head; | |
oldLemon = lemon; | |
for (Node* lemon = this->head; lemon != NULL; oldLemon = lemon, lemon = lemon->next) { | |
if (lemon->data == data) { | |
if (oldLemon == NULL) { | |
this->head = lemon->next; | |
} else { | |
oldLemon->next = lemon->next; | |
} | |
return; | |
} | |
} | |
} | |
bool LinkedList::searchNode(int data) { | |
Node* lemon = this->head; | |
lemon = lemon->next; | |
if (lemon == NULL) | |
return false; | |
else { | |
while ( lemon->data != data ) | |
{ | |
if (lemon->next == NULL) | |
return false; | |
lemon = lemon->next; | |
} | |
return true; | |
} | |
} | |
void LinkedList::printList() { | |
Node* lemon = this->head; | |
lemon = lemon->next; | |
cout << "List:("; | |
while ( lemon != NULL ) { | |
if (lemon->next == NULL) { | |
cout << lemon->data; | |
lemon = lemon->next; | |
} | |
else { | |
cout << lemon->data << ", "; | |
lemon = lemon->next; | |
} | |
} | |
cout << ")"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hudson Jameson | 12/9/2011 | BinaryTree | |
class LinkedList { | |
private: | |
Node *head; | |
public: | |
LinkedList(); | |
void addNode(int data); | |
void removeNode(int data); | |
bool searchNode(int data); | |
void printList(); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hudson Jameson | 12/9/2011 | BinaryTree | |
#include <iostream> | |
#include <stdlib.h> | |
#include "Node.h" | |
#include "LinkedList.h" | |
using namespace std; | |
int main() { | |
int x; | |
int input; | |
LinkedList* newSelection = new LinkedList(); | |
cout<<"Hudson Jameson\nSelect:\n1: To Add a Node\n2: To Remove a Node\n3: To Search for a Node\n4: To Exit\n"; | |
cin >> x; | |
cout<<"You entered: "<< x <<"\n"; | |
cin.get(); | |
while (x!=4) | |
{ | |
switch (x) { | |
case 1: | |
cout << "Enter Node: "; | |
cin >> input; | |
newSelection->addNode(input); | |
break; | |
case 2: | |
cout << "Enter Node: "; | |
cin >> input; | |
if (newSelection->searchNode(input) == true) { | |
cout << "Node found." << endl; | |
newSelection->removeNode(input); | |
break; | |
} | |
else if (newSelection->searchNode(input) == false) { | |
cout << "Node not found." << endl; | |
} | |
else {cout << "Error!!!";} | |
break; | |
case 3: | |
cout << "Enter Node: "; | |
cin >> input; | |
if (newSelection->searchNode(input) == true) { | |
cout << "Node found." << endl; | |
} | |
else if (newSelection->searchNode(input) == false) { | |
cout << "Node not found." << endl; | |
} | |
else {cout << "Error!!!";} | |
break; | |
default: | |
cout << "Error: Select numbers 1-4." << endl << "Select:\n1: To Add a Node\n2: To Remove a Node\n3: To Search for a Node\n4: To Exit" << endl; | |
} | |
newSelection->printList(); | |
cout << endl; | |
cin>>x; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hudson Jameson | 12/9/2011 | BinaryTree | |
#include "Node.h" | |
Node::Node (int data) { | |
this->data = data; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hudson Jameson | 12/9/2011 | BinaryTree | |
class Node { | |
public: | |
Node(int data); | |
int data; | |
Node *next; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment