-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddition.cpp
More file actions
47 lines (42 loc) · 814 Bytes
/
addition.cpp
File metadata and controls
47 lines (42 loc) · 814 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
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int data){
this->data = data;
next = NULL;
}
};
void append(Node** head_ref,int data){
Node* newNode = new Node(data);
Node* head = *head_ref;
if(head == NULL){
*head_ref = newNode;
}else{
while(head->next){
head = head->next;
}
head->next = newNode;
}
return;
}
void push(Node** head_ref,int data){
Node* newNode = new Node(data);
newNode->next = *head_ref;
*head_ref = newNode;
return;
}
void printList(Node* head){
while(head){
cout<<head->data<< ' ';
head = head->next;
}
}
int main(){
Node* head = NULL;
push(&head,2);
append(&head,12);
printList(head);
}