-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram167.c
More file actions
58 lines (48 loc) · 1002 Bytes
/
Program167.c
File metadata and controls
58 lines (48 loc) · 1002 Bytes
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
#include<stdio.h>
#include<stdlib.h>
#pragma pack(1)
struct node
{
int data;
struct node *next;
};
typedef struct node NODE;
typedef struct node * PNODE;
typedef struct node ** PPNODE;
void InsertFirst(PPNODE First, int No)
{
// Step1 : Allocate the memory for new node
PNODE newn = (PNODE)malloc(sizeof(NODE));
// Step2: Initialise the node
newn->data = No;
newn->next = NULL;
// Step3: Check Linked list is empty or not
if(*First == NULL)
{
*First = newn;
}
else // If linked list contains atleast one node
{
newn->next = *First;
*First = newn;
}
}
void Display(PNODE First)
{
printf("Elements of Lin ked List are : \n");
while(First != NULL)
{
printf("%d\t",First->data);
First = First->next;
}
printf("\n");
}
int main()
{
PNODE Head = NULL;
InsertFirst(&Head, 51);
InsertFirst(&Head, 21);
InsertFirst(&Head, 11);
Display(Head);
return 0;
}