Need Help with Test File
Use the data.txt file for your test
Implementation files compile fine but nothing shows in output
Program must output value of head pointer, and be able to output list with 5 elements per line.
listTestUse.cpp
.h files
Imp files
data.txt file
1 2 3 #include
#include #include "linkedlist.h" using namespace std; int main() { 4 5 6 int temp = 7 8 e; 9 0 //opening data.txt ifstream inFile; infile.open("data.txt"); 1 2 3 // Creating a instance of the linked list. linkedList list; 4 5 6 7 8 //Takes data from data.txt and adds it to the linked list for(int i; i > temp; list.addNum(temp); } 9 1 2 3 4 5 1/prints the linked list, finds a number in the linked list, and removes a number from the linked list. list.printList(); list.findNum(); list.removeNum(260); 6 7 8 list.addNum(65); list. findNum(@); list.printList(); 9 0 1 //closing data.txt inFile.close(); 2 3 4 return @; 5 } 1 O NOWN Hifndef NODE #define NODE class node{ public: node(); void setNextPtr(node*); node* getNextPtr(); void setData(int); int getData(); 8 9 10 11 12 13 14 15 private: node *ptr; int intData; }; #endif Hifndef LINKED_LIST #define LINKED_LIST OY W NA 3 4 5 6 7 #include "node.h" class linked List : protected node{ public: void addNum(int); void removeNum(int); void findNum(int); void printList(); linkedlist(); 8 9 Le 1 12 13 14 15 16 17 private: node *head; node *next; node *current; }; 18 19 #endif else { 19 20 23 + linked Listimp.cpp > linked List:removeNum(int) 1 #include "linkedList.h" 2 #include 3 using namespace std; 4 5 //Creates and adds nodes to the list 6 void linkedList::addNum(int num) { 7 node* n = new node(); //creates new node labeled "n" 8 8 9 g 2 n->setData(num); 10 n->setNextPtr(NULL); //uses new node to set Data to num and Next Ptr to NULL 11 12 if(head == NULL) //if list is empty set n for head 13 head = n; 14 15 16 current = head; //set head node to equal current 17 next = head->getNextPtr(); 18 while(next != NULL) { //loop to get last node in list to equal current next = current; 21 current = current->getNextPtr(); 22 } current->setNextPtr(n); //set current to equal n 24 } 25 } 26 27 //Removes a number from the linked list. 28 void linkedList::removeNum(int num) { 29 if(head != NULL) //check to confirm list is not empty 39 31 if(head->getData() == num){ //if num is in head node, remove head node 32 current = head; 33 head = head->getNextPtr(); //set current to head, then assign head to next node 34 current->setNextPtr(NULL); //set next after current to NULL 35 delete current; //delete current 36 } 37 38 else{ //if num is not present in head node 39 current = head; 40 next = head->getNextPtr(); //set next to equal node next to head 41 * 42 while(next != NULL) { //loop the list until num is found or list ends 43 if(next->getData() == num) //if num is found exit loop 44 45 current = next; next = next->getNextPtr(); 47 } break; 46 48 //if num is found in list delete node 49 50 51 52 53 54 55 56 if(next != NULL) { current->setNextPtr(next->getNextPtr(); next->setNextPtr(NULL); delete next; } } 2 57 58 59 //Trys to find a number in the linked list. void linked List::findNum(int num){ if(head != NULL) { current = head; 1/set current to head 60 61 62 63 64 65 66 67 while(current != NULL) { //loop through list if(current->getData() == num) break; //if num found exit loop current = current->getNextPtr(); } 68 69 70 71 72 if(current != NULL) coutgetData()getNextPtr(); //loop over end of list and displaying elements } cout node::getData 1 #include "node.h" 2 #include 3 using namespace std; 4 5 // Node constructor 6 node:: node(){ 7 8 ptr = NULL; 9 intData = 0; 10 } 11 12 //Sets the Next Pointer 13 void node::setNextPtr(node* inptr){ 14 ptr = intr; 15 } 16 17 //Returns the next Pointer 18 node* node::getNextPtr() { 19 return ptr; 20 } 21 22 //Sets the data in the node 23 void node::setData(int intData) { 24 intData = intData; 25 } 26 27 1/Returns the data from the node 28 int node::getData() 29 return intData; 30 B data - Notepad File Edit Format View Help |-255 -844 260 0 94 607 369 -468 -650 59