Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions DS assignment 3/Program_to_Create_a_linked_list.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//DSA

//Write a program to create a linkedList

//Name-Sai Prashant Saxena
//Roll no-02220902719

#include <stdio.h>
#include <stdlib.h>

Expand All @@ -20,10 +16,10 @@ int main()
struct node *head = (struct node *)malloc(sizeof(struct node));
struct node *temp = head;
printf("Hello there!!");
printf("\nWant to create a linked list press Y.....\n\t\t");
printf("\nWant to create a linked list press 1.....\n\t\t");
char c;
scanf("%c", &c);
if (c == 'Y' || c == 'y')
if (c == 1)
{
printf("Enter the value of head\n ");
int value;
Expand All @@ -40,11 +36,12 @@ int main()
}

int ch;
addNode:
printf("Want to add more values to linked list press 1...\n ");
scanf("%d", &ch);
if (ch == 1)
{
addNode:

printf("Enter the next value\n ");
int value;
scanf("%d", &value);
Expand All @@ -62,18 +59,9 @@ int main()
printList(head);
goto end;
}
printf("Want to add more values to linked list press 1...\n ");
scanf("%d", &ch);
if (ch == 1)
{
goto addNode;
}
else
{
printf("Your Linked List..\n");
printList(head);
}


goto addNode;

end:
return 0;
}
Expand All @@ -83,7 +71,7 @@ void printList(struct node *head)
printf("\n");
while (temp != NULL)
{
printf("-->%d Address of node: %d",temp->info,temp);
printf("-->%d ",temp->info);
printf("\t Next:%d\n",temp->link);
temp = temp->link;
}
Expand Down