-
-
Save Venkat-Swaraj/f29b7c8e15528d46634bb6ff606f6c8d to your computer and use it in GitHub Desktop.
Linked List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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