online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. ******************************************************************************* /* package codechef; // don't place package name! */ import java.util.Scanner; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here //Scanner sc =new Scanner(System.in); // BufferedReader bi = new BufferedReader( // new InputStreamReader(System.in)); BufferedReader b =new BufferedReader( new InputStreamReader(System.in)); int t=Integer.parseInt(b.readLine()); //int t=sc.nextInt(); while(t-->0) { int n=Integer.parseInt(b.readLine()); //int n=sc.nextInt(); int a[]=new int[n]; String ar[]; int i; ar=(b.readLine()).split(" "); // for(i=0;i<n;i++) // { // a[i]=Integer.parseInt(ar[i]); // //a[i]=sc.nextInt(); // } mergesort(ar,0,n-1);//mergesort TLE (2.01S) //Arrays.sort(a);TLE (2.01S) //insertion(a,n);//TLE(2.01S) //quickSort(a,0,n-1);//TLE(2.01S) //selection(a,n);//TLE(2.01S) //countSort(a,n); for(i=0;i<n;i++) System.out.print(ar[i]+" "); System.out.println(); } } static void mergesort(String ar[], int i, int j) { if(i<j){ int mid=(i+j)/2; mergesort(ar,i,mid); mergesort(ar,mid+1,j); merge(ar,i,mid,mid+1,j); } } static void merge(String ar[],int s1,int e1,int s2,int e2) { int i=s1; int j=s2; int k=0; String temp[]=new String[e2-s1+1]; while(i<=e1 && j<=e2) { //if(Integer.parseInt(ar[i])<Integer.parseInt(ar[j])) if(ar[j].compareTo(ar[i])>0) temp[k++]=ar[i++]; else temp[k++]=ar[j++]; } while(i<=e1) temp[k++]=ar[i++]; while(j<=e2) temp[k++]=ar[j++]; for(i=s1,j=0;i<=e2;i++,j++) { ar[i]=temp[j]; } } /* static void insertion(int ar[],int n) { int i,j; for(i=1;i<n;i++) { int key=ar[i]; j=i-1; while(j>=0 && ar[j]>key) { ar[j+1]=ar[j]; j--; } ar[j+1]=key; } } static void selection(int ar[],int n) { int i,min,j; for(i=0;i<n;i++) { min=i; int key=ar[i]; for(j=i;j<n;j++){ if(ar[j]<ar[min]) { min=j; } } ar[i]=ar[min]; ar[min]=key; } } static void quickSort(int ar[],int s,int e) {int i=s,j=e,temp; if(s<e) { int pivot = s; while(i<j) { while(ar[i]<=ar[pivot] &&(i<j)) {i++;} while(ar[j]>ar[pivot] &&(i<=j)) {j--;} if(i<j){ temp=ar[i]; ar[i]=ar[j]; ar[j]=temp; } } temp=ar[pivot]; ar[pivot]=ar[j]; ar[j]=temp; quickSort(ar,s,j-1); quickSort(ar,j+1,e); } } // static int getMax(int[] a, int n) { // int max = a[0]; // for(int i = 1; i<n; i++) { // if(a[i] > max) // max = a[i]; // } // return max; //maximum element from the array // } static void countSort(int[] a, int n) // function to perform counting sort { int[] output = new int [n+1]; // int max = getMax(a, n); int max = 100; //int max = 42; int[] count = new int [max+1]; //create count array with size [max+1] for (int i = 0; i <= max; ++i) { count[i] = 0; // Initialize count array with all zeros } for (int i = 0; i < n; i++) // Store the count of each element { count[a[i]]++; } for(int i = 1; i<=max; i++) count[i] += count[i-1]; //find cumulative frequency /* This loop will find the index of each element of the original array in count array, and place the elements in output array*/ /* for (int i = n - 1; i >= 0; i--) { output[count[a[i]] - 1] = a[i]; count[a[i]]--; // decrease count for same numbers } for(int i = 0; i<n; i++) { a[i] = output[i]; //store the sorted elements into main array } } */ // /* Function to print the array elements */ // void printArray(int a[], int n) // { // int i; // for (i = 0; i < n; i++) // System.out.print(a[i] + " "); // } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue