-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab5_Q2.cpp
More file actions
42 lines (42 loc) · 748 Bytes
/
Lab5_Q2.cpp
File metadata and controls
42 lines (42 loc) · 748 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
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node*next;
Node(int d){
data=d;
next=NULL;
}
};
void insertatail(Node*&head,Node*&tail,int val){
Node*temp=new Node(val);
if(head==NULL){
head=temp;
tail=temp;
}else{
tail->next=temp;
tail=temp;
}
}
int getlength(Node*head,int cnt){
Node*temp=head;
if(head==NULL){
return cnt;
}
return getlength(temp->next,cnt+1);
}
int main(){
Node*head=NULL;
Node*tail=NULL;
insertatail(head,tail,1);
insertatail(head,tail,9);
insertatail(head,tail,1);
insertatail(head,tail,2);
insertatail(head,tail,5);
insertatail(head,tail,4);
insertatail(head,tail,3);
int cnt=0;
int length=getlength(head,0);
cout<<"Length of LinkList is "<< length<<endl;
}