SHARE
TWEET

Untitled

a guest Apr 18th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9.     int V[30],n,p,j=0;
  10.     cin >> p;
  11.     cin >> n;
  12.     bool start = true;
  13.     for(int i = 1; i<=n; i++){
  14.         cin >> V[i];
  15.     }
  16.     while(start){
  17.     start = false;
  18.     j++;
  19.     for(int i = 1; i<=n-j; i++){
  20.         if(i <= p){
  21.         if(V[i] > V[i+1]){
  22.             int temp = V[i];
  23.             V[i] = V[i+1];
  24.             V[i+1] = temp;
  25.             start = true;
  26.             }
  27.         }
  28.         else{
  29.             if(V[i] < V[i+1]){
  30.             int temp = V[i];
  31.             V[i] = V[i+1];
  32.             V[i+1] = temp;
  33.             start = true;
  34.         }
  35.     }
  36.     }
  37.     }
  38.     for(int i = 1; i<=n; i++){
  39.         cout << V[i] << " ";
  40.     }
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top