Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to complet this following program few codes that I still need to add

ID: 3621132 • Letter: I

Question

I need help to complet this following program few codes that I still need to add:

// This is the implementation file for the method that deletes the ith item
// from a list of a ListClass object

#include "inlab6.h"
#include "structs.h"

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

//Function to delete the ith node from the list
// If there are fewer than i nodes in the list, an error is returned.
void ListClass::deleteIthNode(int i)
{
NodePtrType q = head; //q will point to the item to delete
NodePtrType prev; //prev will point to the item before q
int j = 1; //j will keep count of which node in the list
// we are currently on

if (head == NULL)
cout<<"Not enough items in list ";
else
{
//Traverse the list to find the ith item
// The following is a while loop that will traverse
// the list until either j == i or the end of the list
// is encountered.

Replace this with a while loop that will traverse
the list until either j == i or the end of the list
is encountered.
(If you delete these instructions, they are repeated in the
comment above the textbox)


//If there are i items in the list, delete the ith one
// The following is the if part of an if-else statement.
// The if part should delete the ith item if there is an
// ith item.

Replace this with the if part of an if-else statement.
The if part should delete the ith item if there is an
ith item.
(If you delete these instructions, they are repeated in the
comment above the textbox)


else
cout<<"Not enough items in list ";
}
}//end of deleteIthNode

Explanation / Answer

#ifndef LISTNODE_H #define LISTNODE_H template class List; template class ListNode { friend class List; public: ListNode(const NODETYPE &); NODETYPE getData() const; void setNextPtr(ListNode *nptr) { nextPtr = nPtr; } ListNode *getNextPtr() const { return nextPtr; } private: NODETYPE data; ListNode *nextPtr; }; template ListNode::list() :firstptr(0),lastptr(0) { } template List::~List() { if(!isEmpty()) { cout nextPtr; lastPtr = currentPtr; currentPtr ->nextPtr = 0; } value = temPtr -> data; delete tempPtr; return true; } } template bool List::isEmpty()const { return firstPtr == 0; } template ListNode *List::getNewNode( const NODETYPE & value) { return new ListNode (value); } template void List::print() const { if(isEmpty()) { cout getData(); previousPtr -> setNextPtr (currentPtr -> getNextPtr()); delete tempPtr; return true; } }while(currentPtr != lastPtr); return false; } } template bool List ::deleteNodeByLocation( NODETYPE & deletedValue, int location) { int count =1 ; if( isEmpty()) return false; if(location < 0) return false; else if(location == 0) return removeFromFront(deletedValue); ListNode * currentPtr = firstPtr -> nextPtr, *previousPtr = firstPtr; while(count nextPtr; count++; } } ListNode *tempPtr = currentPtr; deletedValue = currentPtr -> getData(); prevoiousPtr -> setNextPtr *(cuurentPtr -> getNextPtr()); delte tempPtr; return true; } #endif #include using std::cout; using std::cin; #include using std::random_access_iterator_tag; using std::srand; using std::srand; #include using std::time; #include "List.h" int main() { srand(time(0)); ListintList; for (int i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote