I tried implementing a queue using std::Vectorvector
, using some properties of vector class. Is there scope for further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
I tried implementing a queue using std::Vector
, using some properties of vector class. Is there scope for further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
I tried implementing a queue using std::vector
, using some properties of vector class. Is there scope for further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
implementation of implementing a queue using vector STLstd::vector
I tried implementing a queue using vector STLstd::Vector
, using some properties of vector class. Is there scope offor further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
implementation of queue using vector STL
I tried implementing queue using vector STL, using some properties of vector class. Is there scope of further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
implementing a queue using std::vector
I tried implementing a queue using std::Vector
, using some properties of vector class. Is there scope for further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
I tried implementing queue using vector STL, using some properties of vector class. Is there scope of further improvement in my code, to make it more efficient?
I tried implementing queue using vector STL, using some properties of vector class. Is there scope of further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
I tried implementing queue using vector STL, using some properties of vector class. Is there scope of further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}
I tried implementing queue using vector STL, using some properties of vector class. Is there scope of further improvement in my code, to make it more efficient?
#include<bits/stdc++.h>
using namespace std;
vector<int> q;
void push(int d){
q.insert(q.end(),d);
}
void pop(){
q.erase(q.begin());
}
int front(){
return *q.begin();
}
int main(){
push(1);
push(2);
push(3);
push(4);
pop();
cout<<front()<<endl;
for(int i=0;i<q.size();i++) cout<<q[i]<<" ";
}