Question
I need help and tied to the requirements please. Exactly part B and D.

2. (20pts) Consider the following linked list (LL is pointing to the sentinel node): 2. (20 points) Consider the following li
0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

#include<stdio.h>

//Declaring the structure of the node
struct node
{
   int data;
   struct node *next;
};

//prints the list
void printlist(struct node *temp)
{
   while(temp != NULL)
   {
       printf("%d ",temp->data);
       temp=temp->next;
   }
   printf(" ");
}

int main()
{
   struct node * LL=NULL,*temp=NULL;
   //Creating the given list
   LL=malloc(sizeof(struct node));  
   LL->data=0;
   LL->next=malloc(sizeof(struct node));
   LL->next->data=6;
   LL->next->next=malloc(sizeof(struct node));
   LL->next->next->data=4;
   LL->next->next->next=malloc(sizeof(struct node));
   LL->next->next->next->data=1;
   LL->next->next->next->next=NULL;
  
  
   printf("Initially the given list ");
   printlist(LL);
   printf("printed by the statement in 'a' ");
   printf("%d %d ",LL->next->next->data,LL->next->data);
  
   //Deleting the last node of the list
   LL->next->next->next=NULL;
   free(LL->next->next->next);
   printf("After Deleting the last node of the list ");
   printlist(LL);
  
   //Creating new node
   struct node *new_=malloc(sizeof(struct node));
   printf("Enter the data should be stored in new node:");
   scanf("%d",&new_->data);
   new_->next=NULL;
  
   //inserting new node between 6 & 4
   temp=LL->next->next;
   LL->next->next=NULL;
   new_->next=temp;
   LL->next->next=new_;
   printf("After inserting the new node between 6 & 4 the list is: ");
   printlist(LL);
}

screenshots:

# include<stdio.h> //Declaring the structure of the node struct node int data; struct node *next; //prints the list void prin

printf (Initially the given listln); printlist (LL) printf (printed by the statement in a ) printf (%d %d , LL->nex

output:

CA Program Files (x86)Dev-CpplConsolePauser.exe Initially the given list 6 41 rinted by the statement in a 4 6 After Deleti

If you have any queries, please comment below.

Please upvote , if you like this answer.

Add a comment
Know the answer?
Add Answer to:
I need help and tied to the requirements please. Exactly part B and D. 2. (20pts)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • Modify the below code to fit the above requirements: struct node { char data; struct node...

    Modify the below code to fit the above requirements: struct node { char data; struct node *next; struct node *previous; } *front, *MyNode, *rear, *MyPointer, *anchor *Valuenode ; typedef struct node node; int Push(char input) { if(IsFull()==1) {   printf("The queue is full. Enter the ‘^’ character to stop.\n"); return -1; } else if (IsFull()==-1) { node *MyNode=(node*)malloc(sizeof(node)); MyNode->data=input; rear->next=MyNode; MyNode->previous=rear; MyPointer=rear=MyNode; return 1; } else { node *MyNode=(node*)malloc(sizeof(node)); node *anchor=(node*)malloc(sizeof(node)); MyNode->data=input; MyPointer=rear=front=MyNode; MyNode->previous=NULL; MyNode->next=NULL; anchor->next=MyNode; return 0; } } char...

  • ^^^ Q3. I am trying to implement double linked list but I was failed to write...

    ^^^ Q3. I am trying to implement double linked list but I was failed to write the code so anyone gives the main Code in the main function   THANK YOU FOR ADVANCE #include<stdio.h> #include<stdlib.h> #include<alloc.h> struct node {      int info;      struct node *lptr,*rptr; }; typedef struct node DL; DL *delete( ) , *insert ( ); void display(); DL *delete(DL *start,int x) {      DL *left,*right,*curr;      curr = start;      if( start == NULL)       {                 printf("\nDoubly...

  • need this updated so it will delete the list and then recreate it again /***********************************************************/ /*...

    need this updated so it will delete the list and then recreate it again /***********************************************************/ /* Header files. */ /***********************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> /***********************************************************/ /* Structure definitions. */ /***********************************************************/ struct node { int data; struct node *right; struct node *left; }; struct trash { struct node *node; struct trash *next; }; /****************************************/ /* BUILD_LIST. */ /****************************************/ void BUILD_LIST(int number2Add, struct node *(*head), struct node *(*tail)) { int i; struct node *previous, *current; *head = NULL; *tail =...

  • ****Using C and only C**** I have some C code that has the function addRecord, to...

    ****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...

  • Codelab question! This is c++. Consider the following code: // Linked Lists: TRAVERSE struct ListNode {...

    Codelab question! This is c++. Consider the following code: // Linked Lists: TRAVERSE struct ListNode { int data; struct ListNode *next; }; Assume that a linked list has been created and head points to a sentinel node. A sentinel node is an empty data node in the beginning of the list. It sometimes holds a sentinel value. The use of sentinel nodes is a popular trick to simplify the insert and delete operations. You may also assume that the list...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • C programming A linked list is a linear data structure that allows us to add and remove items fro...

    c programming A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. We have studied the doubly-linked, circular, with a dummy-header-node version of a linked list. In the class notes we studied several functions to manipulate a Linked List. For this assignment you must write the code for the following additional linked list functions: addFirst,...

  • 5 & 6 Name: lue for a, b, and d? what's the 5. A). Summarize the...

    5 & 6 Name: lue for a, b, and d? what's the 5. A). Summarize the master method. (opis) R) Anoly master method to the following case. What s the value for a, b, and dy running time for the function? (10pts) int factorial(int n) else if(n > 1) return n * factorial(n - 1); return 1; 6. What is the output of following function for start pointing to first node of following linked list? 6->5->4->3->2->1 void fun (struct node*...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT