Create linked list using c by taking input from the user
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
int display(){
struct node *ptr;
if(ptr==NULL){
printf("Not found");
return 0;
}
else{
while(ptr!=NULL){
printf("%d",ptr->data);
ptr=ptr->next;
}
}
}
void insert(int n){
struct node *newnode;
int i,_data;
for(i=0;i<n;i++){
newnode=(struct node *)malloc(sizeof(struct node));
if(newnode==NULL){
printf("Memory full");
}
else{
printf("Enter element");
scanf("%d",&_data);
newnode->data=_data;
newnode->next=NULL;
}
}
}
int main(){
int n;
printf("Enter no of element you want to add;");
scanf("%d",&n);
insert(n);
display();
return 0;
}
Create linked list using c by taking input from the user
Reviewed by Shubham Prajapati
on
July 04, 2023
Rating:
No comments:
If you have any doubt so you can comment me then i will 100% help you ,Through comment Chat