Untitled
unknown
plain_text
2 years ago
1.0 kB
8
Indexable
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}nd;
nd* insert_last(nd *start)
{
nd *nw,*p;
nw=(nd*)malloc(sizeof(nd));
printf("enter the element in new node\n");
scanf("%d",&nw->data);
p=start;
while(p->next!=NULL)
{
p=p->next;
}
p->next=nw;
nw->next=NULL;
return start;
}
nd* create(int n)
{
nd *start, *nw,*p,*q;
int i;
nw=(nd*)malloc(sizeof(nd));
printf("enter the element in 1st node\n");
scanf("%d",&nw->data);
start=nw;
nw->next=NULL;
p=start;
for(i=0;i<n-1;i++)
{
nw=(nd*)malloc(sizeof(nd));
printf("enter the element for node\n");
scanf("%d",&nw->data);
nw->next=NULL;
p->next=nw;
p=p->next;
}
return start;
}
int main()
{
int num;
nd *start1,*q;
printf("enter the element size of node \n");
scanf("%d",&num);
start1=create(num);
start1=insert_last(start1);
q=start1;
printf("start");
while(q!=NULL)
{
printf("->%d",q->data);
q=q->next;
}
return 0;
}Editor is loading...