-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountnode.c
More file actions
62 lines (56 loc) · 1.04 KB
/
countnode.c
File metadata and controls
62 lines (56 loc) · 1.04 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
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node * link;
}Node;
Node * head = NULL;
Node * tail = NULL;
void add_ele(){
Node * P = (Node *)malloc(sizeof(Node));
printf("Enter Data :");
int d;
scanf("%d",&d);
P->data = d;
P->link = NULL;
if(head == NULL){
head = P;
tail = P;
}else{
tail->link = P;
tail = P;
}
}
int count_node(){
if(head == NULL)
return 0;
else{
Node * p = head;
int count =0;
while(p!=NULL){
count++;
p = p->link;
}
return count;
}
}
int main(){
printf("1.Add Node\n2.Count Node\n3.Exit\n");
while(1){
int o,p;
printf("Enter choice :");
scanf("%d",&o);
switch (o){
case 1:
add_ele();
break;
case 2:
p= count_node();
printf("No. of Nodes = %d",p);
break;
case 3:
return 0;
}
}
}