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

Write a program that contains the functions called insertEntry() to insert a new

ID: 3740232 • Letter: W

Question

Write a program that contains the functions called insertEntry() to insert a new entry into a linked list and removeEntry() to remove an entry from a linked list. Have insertEntry() take as arguments a pointer to the list entry to be inserted (of type struct entry as defined in class and below), and a pointer to an element in the list after which the new entry is to be inserted. The sole argument to removeEntry() should be a pointer to the list. Have the function remove the entry after the one pointed to by the argument. Why can’t you remove the entry pointed to by the argument? insertEntry() only inserts an element after an existing element in the list, thereby preventing you from inserting a new entry at the front of the list. We overcome this by setting up a special entry structure that points to the beginning of the list, given by nBeginning in the starter code.

use visual studio C, not C++

Explanation / Answer

/* PROGRAM LINKED LIST */

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<alloc.h>

struct SLL

{

int item;

struct SLL *next;

};

struct SLL *nBeggining=NULL;

void insertEntry(int d,int l)

{

struct SLL *t,*ptr,*prev;

int count=1;

t=(struct SLL*)malloc(sizeof(struct SLL));

t->item=d;

t->next=NULL;

if(nBeggining==NULL)

{

nBeggining=t;

return;

}

ptr=nBeggining;

prev=ptr;

while(ptr!=NULL && count<l)

{

prev=ptr;

ptr=ptr->next;

count=count+1;

}

t->next=prev->next;

prev->next=t;

return;

}

void deleteEntry(int d)

{

struct SLL *ptr,*prev;

if(nBeggining==NULL)

{

printf(" Empty list");

return;

}

if(nBeggining->item==d)

{

ptr=nBeggining;

nBeggining=nBeggining->next;

printf(" Element Removed Sucessfully ");

free(ptr);

return;

}

ptr=nBeggining;

while(ptr->next!=NULL && ptr->item!=d)

{ prev=ptr;

ptr=ptr->next;

}

if(ptr=NULL){

printf(" Element not found ");

return;

}

prev->next=ptr->next;

free(ptr);

printf(" Element Deleted Succesfully ");

}

void showList()

{

struct SLL *ptr;

ptr=nBeggining;

if(ptr==NULL) {

printf(" List is empty ");

return; }

printf(" Elements in List are.... ");

while(ptr!=NULL)

{

printf(" %d",ptr->item);

ptr=ptr->next;

}

}

void main()

{

int ch=0,opt=0;

int item,pos;

clrscr();

while(ch!=4)

{

printf(" Single linked lists operators");

printf(" 1.Insert into List");

printf(" 2.Delete from List");

printf(" 3.Show List");

printf(" 4.Exit");

printf(" Enter choice :");

scanf("%d",&ch);

switch(ch)

{

case 1 :

printf(" Enter position :");

scanf("%d",&pos);

printf(" Enter item to insert :");

scanf("%d",&item);

insertEntry(item,pos);

break;

case 2 : printf(" Enter item to Delete :");

scanf("%d",&item);

deleteEntry(item);

break;

case 3: showList();

break;

}

}

}

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