Generation

generate functionWed, 17 May 2023

reate and display Singly Linked List. Test Data : Input the number of nodes : 3 Input data for node 1 : 5 Input data for node 2 : 6 Input data for node 3 : 7 Expected Output : Data entered in the list : Data = 5 Data = 6 Data = 7

#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; void create(struct node **); void display(struct node *); int main() { struct node *p = NULL; create(&p); display(p); return 0; } void create(struct node **head) { int c, ch; struct node *temp, *rear; do { printf("Input the number of nodes : "); scanf("%d", &c); for (int i = 0; i < c; i++) { temp = (struct node *)malloc(sizeof(struct node)); printf("Input data for node %d : ", i + 1); scanf("%d", &temp->data); temp->next = NULL; if (*head == NULL) { *head = temp; } else { rear->next

Questions about programming?Chat with your personal AI assistant