Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Today at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Jun 11, 2026
Ad icon
Wechat qr verification
Pawan2005
Updated:
Jun 11, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Jobs & Employment
Programming interview - written tests
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Anonymous_Abstract" data-source="post: 24659386" data-attributes="member: 568286"><p><span style="font-size: 18px"> Code Of Quick Sort</span></p><p><span style="font-size: 15px"><span style="color: Blue">package com.benz.test;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"></span></span></p><p><span style="font-size: 15px"><span style="color: Blue">public class Quick {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> public int partition(int[] arr,int low,int high)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int pivot = high;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int l = low-1;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> for(int j=low;j<=high-1;j++)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> if(arr[j]<=arr[pivot])</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> l+=1;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> swap(l,j,arr);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> swap(l+1,high,arr);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> return l+1;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> public int[] swap(int x,int y,int[] A)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int temp = A[x];</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> A[x] = A[y];</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> A[y] =temp;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> return A;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> public void quickSort(int[] arr,int low,int high)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> if(low>=high)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> return;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }else {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int z = partition(arr,low,high);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> quickSort(arr,low,z-1);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> quickSort(arr,z+1,high);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> public void show(int[] arr)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> for(int i : arr)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> System.out.print(i+"\t");</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> public static void main(String[] args)</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> {</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> Quick qu = new Quick();</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int[] arr= {20,10,15,40,50,60,45};</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int high = arr.length-1;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> int low=0;</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> qu.quickSort(arr, low, high);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> System.out.println("Sorted Array");</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> qu.show(arr);</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> </span></span></p><p><span style="font-size: 15px"><span style="color: Blue"> }</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"></span></span></p><p><span style="font-size: 15px"><span style="color: Blue">}</span></span></p><p><span style="font-size: 15px"><span style="color: Blue"></span></span></p></blockquote><p></p>
[QUOTE="Anonymous_Abstract, post: 24659386, member: 568286"] [SIZE="5"] Code Of Quick Sort[/SIZE] [SIZE="4"][COLOR="Blue"]package com.benz.test; public class Quick { public int partition(int[] arr,int low,int high) { int pivot = high; int l = low-1; for(int j=low;j<=high-1;j++) { if(arr[j]<=arr[pivot]) { l+=1; swap(l,j,arr); } } swap(l+1,high,arr); return l+1; } public int[] swap(int x,int y,int[] A) { int temp = A[x]; A[x] = A[y]; A[y] =temp; return A; } public void quickSort(int[] arr,int low,int high) { if(low>=high) { return; }else { int z = partition(arr,low,high); quickSort(arr,low,z-1); quickSort(arr,z+1,high); } } public void show(int[] arr) { for(int i : arr) { System.out.print(i+"\t"); } } public static void main(String[] args) { Quick qu = new Quick(); int[] arr= {20,10,15,40,50,60,45}; int high = arr.length-1; int low=0; qu.quickSort(arr, low, high); System.out.println("Sorted Array"); qu.show(arr); } } [/COLOR][/SIZE] [/QUOTE]
Insert quotes…
Verification
Payakata winadi keeyak tibeda?
Post reply
Top
Bottom