0% found this document useful (0 votes)
34 views

Linked List Program Example

This document contains C code to create a singly linked list. It defines a struct node with data and next pointer fields. The create() function allocates nodes, gets user input for the data, and links the nodes together into a list starting at the start pointer. The display() function prints out the linked list by traversing from the start node to the NULL end. The main() function calls create() to build the list, then calls display() to output it.

Uploaded by

shreetam behera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Linked List Program Example

This document contains C code to create a singly linked list. It defines a struct node with data and next pointer fields. The create() function allocates nodes, gets user input for the data, and links the nodes together into a list starting at the start pointer. The display() function prints out the linked list by traversing from the start node to the NULL end. The main() function calls create() to build the list, then calls display() to output it.

Uploaded by

shreetam behera
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
#include<string.h>
//------------------------------------------------struct node
{
int data;
struct node *next;
}*start=NULL;
//------------------------------------------------------------

void create()
{
char ch;
do
{
struct node *new_node,*current;

new_node=(struct node *)malloc(sizeof(struct node));

printf("nEnter the data : ");


scanf("%d",&new_node->data);
new_node->next=NULL;

if(start==NULL)
{
start=new_node;
current=new_node;
}
else
{
current->next=new_node;
current=new_node;

printf("nDo you want to creat another : ");


//scanf("%c",&ch);
ch=getchar();
}while(ch!='n');
}
//------------------------------------------------------------------

void display()
{
struct node *new_node;
printf("The Linked List : n");
new_node=start;
while(new_node!=NULL)
{
printf("%d--->",new_node->data);
new_node=new_node->next;
}
printf("NULL");
}
//---------------------------------------------------void main()
{
create();
display();
}
//----------------------------------------------------

You might also like