https://www.bybit.com/register?affiliate_id=38000&group_id=52135&group_type=1
[856x508] Get $90 Rewards

C Programming code | Read & Display Nodes in linked lists | Data Structure

Write a Modular C Programming code for Operations ( Read & Display ) used in Nodes of Singly linked list | Data Structure.

Read & Display the Data given to the node. 

Refer to Notes: Notes on Data Structures And Algorithms – Linked List

CODE:

#include<stdio.h>
#include<stdlib.h>
struct node
{
 int data;
 struct node *next;
};
struct node *head;
struct node* insert_at_end(struct node *);
void display(struct node *);
struct node *temp,*temp1,*newnode;
main()
{
int ch,p=0,n;
head=NULL;

printf("\nEnter the Number of Nodes you want!: ");
scanf("%d",&n);

             printf("\nEnter the Datails of Nodes:\n");
             while(p!=n)
             {
             newnode=(struct node*)malloc(sizeof(struct node));
             scanf("%d",&newnode->data);
             head=insert_at_end(newnode);
             p++;
             }
printf("\nThe nodes data You have entered are:\n");
display(head);
}
struct node* insert_at_end(struct node *newnode)
{
   if(head==NULL)
   {
     head=newnode;
     head->next=NULL;
     return(head);
   }
   else
   {
     temp=head;
     while(temp->next!=NULL)
     {
        temp=temp->next;

     }
     temp->next=newnode;
        newnode->next=NULL;
        return(head);

   }
}
void display(struct node *head)
{
   if(head==NULL)
   {
     printf("The linked list is empty\n");
   }
   else
   {
      temp=head;
      while(temp!=NULL)
      {
         printf("%d->",temp->data);
         temp=temp->next;
      }
      printf("\n");
   }
}

OUTPUT

Enter the Number of Nodes you want!: 5

Enter the Datails of Nodes:
6
3
2
1
3

The nodes data You have entered are:
6->3->2->1->3->

Process returned 0 (0x0)   execution time : 7.569 s
Press any key to continue.

© Credits

Supreet Palankar (2) 
'H' div
Department of Computer Science


(  ) — Number of Contributions!

Please find some more codes of 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, and MISC on the below page:

Top 100+ C Programming codes – KLE Technological University

 

Leave a Comment