-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlist.cpp
64 lines (52 loc) · 962 Bytes
/
linkedlist.cpp
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 <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;i++)
#define pr pair<int,int>
#define vec vector<int>
#define MP map<pr,string>
#define MB map<pair,bool>
#define unmp unordered_map<int,int>
#define ft first
#define sd second
using namespace std;
struct Link{
int data;
Link* right;
Link* left;
};
void Travers(Link* x){
Link *l = x;
Link *r = x;
//head->next = NULL;
cout<<'\t'<<x->data<<'\t'<<endl;
while(r!= NULL){
cout<<"Data : "<<r->data<<endl;
r=r->left;
}
}
int main(){
int a[]={2,5,4,3,6,7,8,9};
Link* head = NULL;
head = new Link();
int i=0;
int len = 8;
head->data = 5;
head->left = head->right = NULL;
while(i<len){
Link* in = new Link();
int input = a[i++];
in->data = input;
in->right = in->left = NULL;
Link *tmp = head;
Link *tmpr = head;
while (tmp != NULL){
if(tmp->data>=input){
tmp = tmp->left;
}
else{
tmp = tmp->right;
}
}
tmp = in;
}
Travers(head);
}