-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from iceybubble/master
Create LinkList.c
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <stdlib.h> | ||
struct node | ||
{ | ||
int data; | ||
struct node *next; | ||
}; | ||
|
||
void main() | ||
{ | ||
struct node *p, *head; | ||
int n, i; | ||
printf("How many nodes to be created\n"); | ||
scanf("%d", &n); | ||
for (i = 0; i < n; i++) | ||
{ | ||
if (i == 0) | ||
{ | ||
head = (struct node *)malloc(sizeof(struct node)); | ||
p= head; | ||
} | ||
else | ||
{ | ||
p->next = (struct node *)malloc(sizeof(struct node)); | ||
printf("Enter the value: "); | ||
scanf("%d", &p->next->data); | ||
} | ||
p = p->next; | ||
} | ||
p->next = NULL; | ||
p = head; | ||
while (p->next != NULL) | ||
{ | ||
printf("%d", p->data); | ||
p = p->next; | ||
} | ||
} |