-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin.cpp
More file actions
100 lines (82 loc) · 1.61 KB
/
in.cpp
File metadata and controls
100 lines (82 loc) · 1.61 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// #include<iostream>
// using namespace std;
// int main(){
// int arr1[] = {10,20,30,80};
// int arr2[] = {2,25,36,75};
// int merge[20];
// int i=0,j=0,k=0;
// while (i<4 && j<4)
// {
// if (arr1[i] < arr2[j])
// {
// merge[k] = arr1[i];
// i++,k++;
// }
// else{
// merge[k] = arr2[j];
// j++,k++;
// }
// }
// while (i<4)
// {
// merge[k] = arr1[i];
// i++,k++;
// }
// while (j<4)
// {
// merge[k] = arr1[j];
// j++,k++;
// }
// for (int x=0;x<k;x++)
// {
// cout <<merge[x]<<" ";
// }
// return 0;
// }
#include<stdio.h>
#include<stdlib.h> //DMA
typedef struct linknode{
int data;
struct linknode *next;
}node;
node *head,*ptr,*temp,*last;
void create_node(){
temp=(node*)malloc(sizeof(node));
printf("Enter element \n");
scanf("%d",&temp->data);
temp->next=NULL;
}
node *reverselinkedlist(node *head){
node *prev=NULL;
node *temp2=NULL;
while(head!=NULL){
temp2=head->next;
head->next=prev;
prev=head;
head=temp2;
}
head=prev;
}
int main(){
int ch;
printf("Enter how many nodes u anna create\n");
scanf("%d",&ch);
for(int i=0;i<ch;i++){
create_node();
if(head==NULL){
head=temp;
last=temp;
}
else {
last->next=temp;
last=temp;
}
}
head = reverselinkedlist(head);
ptr=head;
while(ptr!=NULL){
printf("%d ",ptr->data);
ptr=ptr->next;
}
return 0;
}