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

hello, i am having trouble deleting the front node of a singly link list this is

ID: 3624196 • Letter: H

Question

hello, i am having trouble deleting the front node of a singly link list

this is my function and i have to use that function


void LL::deleteFront(el_t& OldNum)
{

if(isEmpty())
{
cout <<"Cant remove from an empty list";
}

else
{
Node *second;
second = front->next;
delete front;
front = second;
}
count--;
}

this is my client program

int main()
{
LL myLL;
el_t OldNum;

myLL.isEmpty();
myLL.displayAll();
myLL.addRear(1);
myLL.addRear(2);
myLL.addRear(3);
myLL.deleteRear(OldNum);
myLL.displayAll();

}

i get a segmentation error, if i take out myLL.deleteRear(OldNum); it does work fine.
please any help on fixing the segmentation fault?

i also try taking out the OldNum out of myLL.deleteRear();

and i get a compiling error

any help on how to get my function to work.
any help please

Explanation / Answer

void LinkedList<Type>:: deleteNode(const Type& deleteItem)
{
nodeType<Type> *current;
nodeType<Type> *trailCurrent;
bool found;

if(first = NULL)
cout<<""Cannot deelte from an the empty lis";
else
{
if(first -> info == deleteItem)
{
current = first;
first = first ->link;
count--;

if(first == NULL)
last = NULL;

delete current;
}

else
{
found = false;
trailCurrent = first;
current = first -> link;
while(current != NULL && ! found)
{
if(currebt -> info != deleteItem)
{
trailCurrent = current;
current = current - >link;

}

if(found)
{
trailCurrent -> link = current --> link;
count--;

if(last == curent)
last= trailCurrent;
delete current;

}