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

Hi! I need some help with coding the folowing in C : In this program, you will i

ID: 3574404 • Letter: H

Question

Hi! I need some help with coding the folowing in C:

In this program, you will implement three operations on a linked list: Insert at the front, traversal, and deletion of a specified value. Here's what I want your program to do:

Build the list:

In a loop, ask the user for a non-zero integer to be inserted into the list (stop this insertion loop when the user enters a value of 0)

Insert the non-zero value at the front of the list

After each insertion, traverse the list and printout each value, so we know that your insertions are working correctly (i.e., that the list is being built properly)

Delete specified values from the list.

When the list is complete (the user has indicated by entering a zero that there are no more values to be inserted), go into a loop where your code asks the user for a value to be deleted and then tries to delete that value from the list.

After each deletion, traverse the list again so that we can see if the deletion worked as expected.

Stop the deletion loop and end your program when the user enters a zero for the value to be deleted.

Here's a sample printout

Enter a value to be inserted: 8
   Here's the list now: 8

Enter a value to be inserted: 5
   Here's the list now: 5 8

Enter a value to be inserted: 17
   Here's the list now: 17 5 8

Enter a value to be inserted: 0

Done building the list.

Enter a value to be deleted: 5
   Here's the list now: 17 8

Enter a value to be deleted: 22
   
22 is not in the list; no deletion was performed

Enter a value to be deleted: 17
   Here's the list now: 8

Enter a value to be deleted: 8
   The list is now empty

Enter a value to be deleted: 2
   The list is empty so no deletion can be performed

Enter a value to be deleted: 0
   All done; program terminating

_________________________________________________________________________________________________________

I have inclided a picture of some code I have so far, clearly its not complete but it does show the direction I want to go in with the project

Thank You!!

fincludekstdio.h> h> typedef struct list Itm int some Integer; struct list Itm *next LIST ITEM LIST ITEM *start NULL: *tempi while some Integer temp malloc size of IST IT printf ("Enter integer:") scanf ("td", & (temp- some Integer) temp next start; start temp IST ITEM trvptr Start while (trvPtr some Integer printf ("i rvPtr somneInteger) trvPtr trvPtr- next: hw12.c: 19: warning: data definition has no type or storage class hw12.c:20: error: expected identifier or before While hw12.c:29: error: initializer element is not constant hw12.c: 30: error: expected identifier or before while hw12.c: 3 befo token

Explanation / Answer

The program for the above question is given below:

#include <stdio.h>

typedef struct list_item // define structure for linkedlist
{
   int data;
   struct node *next;
}nod;

void insert_front(nod **start,int data) // insert at the front of list
{
   nod *temp = NULL;
   temp = (nod *)malloc(sizeof(nod));
   temp->data = data;
   temp->next = NULL;
   if (NULL == *start)
   {
       *start = temp;
   }
   else
   {
       temp->next = (*start);
       (*start) = temp;
   }
}
void display(nod *temp) //display the list
{
   if (NULL == temp)
   {
       printf("The list is now empty ");
       return;
   }
   printf("Here's the list now ");
   while (NULL != temp)
   {
       printf("%d ",temp->data);
       temp = temp->next;
   }
}
void delete_value(nod **start,int data) //delete a value from list
{
   nod *temp = (*start);
   nod *prev = NULL;
   if (temp->data == data)
   {
       (*start) = temp->next;
       free(temp);
       return;
   }
   while ((NULL != temp) && (temp->data != data))
   {
       prev = temp;
       temp = temp->next;
  
   }

   if (NULL == temp)
   {
       printf("%d is not in the list; no deletion was performed ",data);
       return;
   }

prev->next = temp->next;
   free(temp);
  

}
int main()
{
   int value;
   nod *start = NULL;
   do
   {
       printf(" Enter the value to be inserted ");
       scanf("%d",&value);
       if(0 != value)
       {
           insert_front(&start,value);
           display(start);
       }
       else
       {
           printf("Done building the list ");
       }
   }
   while(value != 0);
   do
   {
       printf(" Enter the value to be deleted ");
       scanf("%d",&value);
       if(0 != value)
       {
           if(NULL != start)
           {
               delete_value(&start,value);
               display(start);
           }
           else
           {
               printf("The list is empty so no deletion can be performed ");
           }
       }
       else
       {
           printf(" All done; program terminating ");
       }
   }
   while(value != 0);
   return 0;
}

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