Skip to main content
Code Review

Return to Question

Typo fix
Source Link
Toby Speight
  • 87.8k
  • 14
  • 104
  • 325

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]<<" ";
 }
copy-edited
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65

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]<<" ";
 }
Post Reopened by Edward, Incomputable, Billal BEGUERADJ, Stephen Rauch, Vogel612
fixed formatting, added some tags
Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

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]<<" ";
 }
Post Closed as "Not suitable for this site" by Zeta, Graipher, πάντα ῥεῖ, Daniel, Billal BEGUERADJ
added 1 character in body
Source Link
Loading
Source Link
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /