Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a Java Expert!

Join 244,306 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 789 people online right now. Registration is fast and FREE... Join Now!




Recursive Array Sorting Help

 
Reply to this topicStart new topic

Recursive Array Sorting Help

zohoor
2 Jan, 2009 - 01:19 PM
Post #1

New D.I.C Head
*

Joined: 30 Dec, 2008
Posts: 1

hi how are u

i need to help plz my homwork it to sorting an arry whith recursion

in java and i rowht it but it dosnt work

CODE

import javax.swing.*;
import java.io.*;

public class asssaja {
       static int i=1;
      static int j=0;  
   static public void sorta(float a[],int x,int y)
   {
       float temp;
        if(j==y)
        return;
      if (a[x]>a[i])
       {
           temp=a[x];
           a[x]=a[i];
           a[i]=temp;
        }
      
    i++;
      sorta( a, j++, y);
        
   }
    
  
    public static void main(String args[])throws IOException{
     int arnum;
     String n,e;
    n= JOptionPane.showInputDialog("pleas enter the number element of array");
    arnum=Integer.parseInt(n);
    float []array=new float[arnum];
     for (int c=0;c<arnum;c++){
        e= JOptionPane.showInputDialog("pleas enter"+(c+1)+"element of array");
        array[c]=Float.parseFloat(e);
     }
    sorta(array,0,arnum-1);
    String output="the element of array by sorted\n";
    JTextArea t=new JTextArea();
    for (int c=0;c<arnum;c++)
        output+=array[c]+"\n ";
    t.setText(output);
    JOptionPane.showMessageDialog(null,t);
    System.exit(0);  
    }
    
  
}




pleas hary

thank you biggrin.gif

User is offlineProfile CardPM
+Quote Post


BetaWar
RE: Recursive Array Sorting Help
2 Jan, 2009 - 01:22 PM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 3,813



Thanked: 203 times
Dream Kudos: 1325
My Contributions
Renamed.
User is online!Profile CardPM
+Quote Post

macosxnerd101
RE: Recursive Array Sorting Help
3 Jan, 2009 - 07:36 AM
Post #3

D.I.C Regular
Group Icon

Joined: 27 Dec, 2008
Posts: 389



Thanked: 15 times
My Contributions
It looks like you're trying to use Bubblesort recursively. Try Mergesort or Quicksort if you need to use recursion. Mergesort works by picking a pivot point and dividing the original collection into 2 sublists based on a comparison to the pivot point. Quicksort works by partitioning the collection based on the pivot point, eliminating the need to merge the sublists into one collection, making it more efficient than Mergesort. Both have a growth of O(n log n) though.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 06:44PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month