-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkedList6.c
64 lines (51 loc) · 1.03 KB
/
LinkedList6.c
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
#include<stdio.h>
#include<stdlib.h>
#include"typedef.h"
struct node
{
int data;
struct node *next;
};
void InsertFirst(PPNODE First, int iNo)
{
PNODE newn = NULL;
//Step 1:- Allocate Dynamic Memory for New Node
newn = (PNODE)malloc(sizeof(NODE));
// Step 2 :- Initialize the new Node
newn->data = iNo;
newn->next = NULL;
// Step 3 :- Check if the linked list is empty
if(*First == NULL)
{
*First = newn;
}
//If Linked List contains atleast one node in it
else
{
newn -> next = *First;
*First = newn;
}
}
int Count(PNODE First)
{
int iCnt = 0;
while(First != NULL)
{
First = First->next;
iCnt++;
}
return iCnt;
}
int main()
{
PNODE Head = NULL;
int iRet = 0;
InsertFirst(&Head,151);
InsertFirst(&Head,101);
InsertFirst(&Head,51);
InsertFirst(&Head,21);
InsertFirst(&Head,11);
iRet = Count(Head);
printf("Number of Elements are %d : \n",iRet);
return 0;
}