how could i implement this function void addbeforeIth(int I, el_t newNum) //will
ID: 3624199 • Letter: H
Question
how could i implement this functionvoid addbeforeIth(int I, el_t newNum)
//will add right before the Ith node. Count is updated.
If I is an illegal value (i.e. > count+1 or < 1)throw an exception
my header file is the following
typedef int el_t;
struct Node
{
el_t elem;
Node *next;
};
class LL
{
private:
//Data members
int count; // how many nodes do we currently have
Node *front;//pointer named front
Node *rear;// pointer named rear
public:
//contructor
LL();
//destructor
~LL();
//PURPOSE:adds a new node at the rear and puts data in the first
// field of this new node
//HOW TO CALL:provide the node that needs to be added
void addRear(el_t NewNum);
//PURPOSE: if queue is empty displays the error, else it gives
// the front new elem
//HOW TO CALL:
void deleteFront(el_t& OldNum);
//PURPOSE:Checks if front and rear are empty
//
//HOW TO CALL:
bool isEmpty();
//PURPOSE:Displays everything in the queue link list
//
//HOW TO CALL:
void displayAll();
//PURPOSE: It will add a new node to the front of the list
// count will be updated
//HOW TO CALL:Provide the element to be added
void addFront(el_t NewNum);
//PURPOSE:It will delete a node from the rear of the list
// count is updated
//HOW TO CALL: provides a holder for the element removed(
// pass by reference)
void deleteRear(el_t& OldNum);
//PURPOSE:will delete the Ith node, count is updated
//HOW TO CALL:Provides a holder for the element to be removed
void deleteIth(int I, el_t OldNum);
//PURPOSE:It will add right before the Ith node. Count is
// is updated
//HOW TO CALL:;Provide a holder for that element
void addbeforeIth(int I, el_t NewNum);
//PURPOSE:
//
//HOW TO CALL:
void destroy();
};
Explanation / Answer
add(const Type& newItem)
{
nodeType<Type> *newNode;
newNode = new nodeType<Type>
newNode -> info = newItem;
newNode -> link = first;
first = newNode;
count++
if(last == NULL)
last = newNode;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.