Skip to content

Instantly share code, notes, and snippets.

@Venkat-Swaraj
Last active September 29, 2022 03:47
Show Gist options
  • Save Venkat-Swaraj/f29b7c8e15528d46634bb6ff606f6c8d to your computer and use it in GitHub Desktop.
Save Venkat-Swaraj/f29b7c8e15528d46634bb6ff606f6c8d to your computer and use it in GitHub Desktop.
Linked List
#include <stdio.h>
#include <stdlib.h>
typedef struct stud{
int roll;
char name[25];
int age;
struct stud *next;
}node;
node *create_list();
void display(node *head);
int main()
{
node *head;
head = create_list();
display(head);
return 0;
}
void display(node *head)
{
int count = 1;
node *tp = head;
while(tp!=NULL)
{
printf("\n node %d: %d,%s and %d",count,tp->roll,tp->name,tp->age);
tp = tp->next;
count ++;
}
printf("\n");
}
node *create_list()
{
int i,n;
node *p,*head;
printf("\n Enter the number of elements to be entered: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i==0)
{
head = (node *)malloc(sizeof(node));
p=head;
}
else
{
p->next = (node *)malloc(sizeof(node));
p = p->next;
}
printf("\n Enter record data: ");
scanf("%d %s %d",&p->roll,p->name,&p->age);
}
p->next = NULL;
return (head);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment