forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinked list
59 lines (54 loc) · 1.12 KB
/
linked list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
typedef struct node
{
int data;
struct node *next;
}node;
int main(){
int n,i;
node *p,*head=NULL,*q;
printf("enter the no. of node: ");
scanf("%d",&n);
printf("enter the value of node: ");
for ( i = 1; i <= n; i++)
{
if(head==NULL){
head=(node*)malloc(sizeof(node));
p=head;
// printf("enter the value of node: ");
scanf("%d",&head->data);
p->next=NULL;
}
else{
p->next=(node*)malloc(sizeof(node));
// printf("enter the value of node: ");
p=p->next;
scanf("%d",&p->data);
p->next=NULL;
}
}
p=head;
printf("your linked list\n");
for(i=1;i<=n;i++)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
printf("insert at front\n");
q=head;
{ p=(node*)malloc(sizeof(node));
p->data=4;
p->next=q;
head=p;
}
p=head;
while (p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
return 0;
}