#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
struct link
{
int data;
struct link *ptr;
}*head=NULL;
void insert()
{
char point;
do
{
struct link *newlink,*currentlink;
newlink=(struct link*)malloc(sizeof(struct link));
printf("\nEnter data into linked list");
scanf("%d",&newlink->data);
newlink->ptr=NULL;
if(head==NULL)
{
head=newlink;
currentlink=newlink;
}
else
{
currentlink->ptr=newlink;
currentlink=newlink;
}
printf("\nDo you want to continue?");
point=getche();
}while(point!='n');
}
void display()
{
struct link *iterator;
iterator=head;
printf("\n Data in your linked list is");
while(iterator!=NULL)
{
printf("%d----->",iterator->data);
iterator=iterator->ptr;
}
printf("NULL");
}
main()
{
insert();
display();
return 0;
}
output
----------------------------------
#include<stdlib.h>
#include<conio.h>
struct link
{
int data;
struct link *ptr;
}*head=NULL;
void insert()
{
char point;
do
{
struct link *newlink,*currentlink;
newlink=(struct link*)malloc(sizeof(struct link));
printf("\nEnter data into linked list");
scanf("%d",&newlink->data);
newlink->ptr=NULL;
if(head==NULL)
{
head=newlink;
currentlink=newlink;
}
else
{
currentlink->ptr=newlink;
currentlink=newlink;
}
printf("\nDo you want to continue?");
point=getche();
}while(point!='n');
}
void display()
{
struct link *iterator;
iterator=head;
printf("\n Data in your linked list is");
while(iterator!=NULL)
{
printf("%d----->",iterator->data);
iterator=iterator->ptr;
}
printf("NULL");
}
main()
{
insert();
display();
return 0;
}
output
----------------------------------
Không có nhận xét nào:
Đăng nhận xét