-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList101.cpp
More file actions
46 lines (33 loc) · 818 Bytes
/
LinkedList101.cpp
File metadata and controls
46 lines (33 loc) · 818 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
//LINKED LIST
#include<iostream>
using namespace std;
struct Node {
Node* next;
int value;
};
int main(){
Node* head = new Node();
int array[] = {7,5,2,1,9,7,};
int n = (sizeof(array))/sizeof(array[0]);
Node* link = head;
//LINKED LIST CONSTRUCTION
for(int i = 0; i < n; i++){
link->value = array[i];
if(i < (n-1)){
link->next = new Node();
link = link->next;
}
}
//LINKED LIST TRAVERSAL
link = head;
while(link != NULL){
cout<<link->value<<endl;
link = link->next;
}
}
/*
1. Do not print the linkedlist.
2. Add a new number to the end of the linkedlist.
3. This new number should be entered by the user.
4. Print entire linkedlist now.
*/