-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathessentials.cpp
More file actions
173 lines (105 loc) · 2 KB
/
essentials.cpp
File metadata and controls
173 lines (105 loc) · 2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include<algorithm>
#include<iostream>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<forward_list>
#include<string>
#include<vector>
#include<map>
#include<deque>
#include<list>
// #include<pair>s
using namespace std;
struct bnode{
struct bnode*left;
struct bnode*right;
int data;
};
struct bnode*newNode(int x){
struct bnode*root=new bnode;
root->left=NULL;
root->right=NULL;
root->data=x;
return root;
}
struct node{
int data;
struct node*next;
};
void move_node(struct node**head,struct node**head2){
struct node*temp=*head;
struct node*ahead=temp->next;
temp->next=*head2;
*head2=temp;
*head=ahead;
}
struct node*push_atend(struct node*head,int data){
struct node*temp=new node;
struct node*temp1=head;
temp->data=data;
if(head==NULL){
head=temp;
temp->next=NULL;
}
else{
while(temp1->next!=NULL){
temp1=temp1->next;
}
temp1->next=temp;
temp->next=NULL;
}
return (head);
}
void print_single_ll(struct node*head){
struct node*temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
template<typename T,typename A>
void print_vector(vector<T,A>const& v1){
for(auto it=v1.begin();it!=v1.end();it++){
cout<<*it<<" ";
}
cout<<endl;
}
void swap(int*a, int*b){
int temp=*a;
*a=*b;
*b=temp;
}
void print_array(int array[],int size){
for(int i=0;i<size;i++){
cout<<array[i]<<" ";
}
cout<<endl;
}
void print_stack(stack<int>s1){
while(!s1.empty()){
cout<<s1.top()<<" ";
s1.pop();
}
}
void print_queue(queue<int>s1){
while(!s1.empty()){
cout<<s1.front()<<" ";
s1.pop();
}
}
void print_maxheap(priority_queue<int>pq){
while(pq.size()!=0){
cout<<pq.top()<<" ";
pq.pop();
}
cout<<endl;
}
void print_minheap(priority_queue<int, vector<int>, greater<int> >pq){
while(pq.size()!=0){
cout<<pq.top()<<" ";
pq.pop();
}
cout<<endl;
}