fork(1) download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. void qsortfirst(pair<int,int> p[],int low,int up){
  6.  
  7. if(low>=up)
  8. return;
  9. pair<int,int> temp;
  10. int i=low+1,j=up,pivot=p[i].first;
  11. while(i<=j){
  12. while(p[i].first<pivot)
  13. i++;
  14. while(p[j].first>pivot)
  15. j--;
  16. if(i<j){
  17. temp=p[i];
  18. p[j]=p[i];
  19. p[i]=temp;
  20. j--;
  21. i++;
  22. }
  23. else if(i==j)
  24. i++;
  25. }
  26. temp=p[j];
  27. p[j]=p[low];
  28. p[low]=temp;
  29. qsortfirst(p[],low,j-1);
  30. qsortfirst(p[],j+1,up);
  31. }
  32.  
  33. int main() {
  34. // your code goes here
  35. pair<int,int> p=new p[5];
  36. for(int i=0;i<5;i++)
  37. cin>>p[i].first>>p[i].second;
  38. qsortfirst(p,0,5);
  39. for(int i=0;i<5;i++)
  40. cout<<p[i].first<<" "<<p[i].second;
  41. return 0;
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1 3
2 4
4 5
3 2
1 6
compilation info
prog.cpp: In function 'void qsortfirst(std::pair<int, int>*, int, int)':
prog.cpp:29:15: error: expected primary-expression before ']' token
  qsortfirst(p[],low,j-1);
               ^
prog.cpp:30:15: error: expected primary-expression before ']' token
  qsortfirst(p[],j+1,up);
               ^
prog.cpp: In function 'int main()':
prog.cpp:35:22: error: 'p' does not name a type
  pair<int,int> p=new p[5];
                      ^
prog.cpp:37:9: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   cin>>p[i].first>>p[i].second;
         ^
prog.cpp:37:21: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   cin>>p[i].first>>p[i].second;
                     ^
prog.cpp:38:18: error: cannot convert 'std::pair<int, int>' to 'std::pair<int, int>*' for argument '1' to 'void qsortfirst(std::pair<int, int>*, int, int)'
  qsortfirst(p,0,5);
                  ^
prog.cpp:40:10: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   cout<<p[i].first<<" "<<p[i].second;
          ^
prog.cpp:40:27: error: no match for 'operator[]' (operand types are 'std::pair<int, int>' and 'int')
   cout<<p[i].first<<" "<<p[i].second;
                           ^
stdout
Standard output is empty