/
Source Code
53 lines (45 loc) · 1.22 KB
/
Source Code
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
#include <stdio.h>
#include <stdlib.h>
struct Node{
int data;
struct Node *next;
};
struct Node* head;
void Insert(int x)
{
struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
temp->data=x;
temp->next;
/* so if we the address of the first inserted element as 100 and then we can do like this set temp->next = head which contains the address of the created node before the second one
and then we can procced to the next step*/
temp->next = head;
/* so if the list is empty only this will run and which says that head has the address of temp* we are dooing this just like in the case of int
int i is the initialization and then we have i= adress of pointer with the &p => i =&p but this is any array so the temp just mean the adress here/
head= temp;
}
void Print()
{
struct Node * temp= head;
printf("List is: ");
while(temp != NULL)
{
printf("%d ", temp->data);
temp= temp->next;
}
printf("\n");
}
int main()
{
head =NULL;
int n, i, x;
printf("How many Numbers?: \n");
scanf("%d", &n);
for(i= 0; i<n; i++)
{
printf("Enter the number: ");
scanf("%d",&x);
Insert(x);
Print();
}
return 0;
}