Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2008, 11:53 AM
Member
 
Join Date: Feb 2008
Posts: 1
dmotah is on a distinguished road
how to wrk with twa threads then compile both to 1 thread
hi, here is the code i've written

import java.io.*;
import java.util.Random;
import java.util.Vector;



public class QuickSortApp
{
int LEN = 20;
int[] arr1 = new int[LEN];
int[] arr2 = new int[LEN];


public static void main(String[] args)
{
int LEN = 20;
int[] arr1 = new int[LEN];
int[] arr2 = new int[LEN];

Random r = new Random();

for (int i = 0; i<arr1.length; i++)
arr1[i] = Math.abs(r.nextInt()%101);



for (int i = 0; i<arr2.length; i++)
arr2[i] = Math.abs(r.nextInt()%101);




System.out.println("Unsorted array1:");
printArray(arr1);

System.out.println("Unsorted array2:");
printArray(arr2);



int[] sorted1 = sort(arr1);
System.out.println("\n\nSorted array1:");
printArray(sorted1);

int[] sorted2 = sort(arr2);
System.out.println("\n\nSorted array2:");
printArray(sorted2);


int array1[]=select(arr1, 70, 80);
if(array1!=null)
System.out.println();
System.out.println("between 70-80 of array1");
printArray(array1);


int array2[]=select(arr2, 70, 80);
if(array2!=null)
System.out.println();
System.out.println("between 70-80 of array2");
printArray(array2);


System.out.println();
System.out.println("Common in both arrays");

if ((common(array1,array2))!=null)
{

printArray(common(array1,array2));
}
else
{
System.out.println("No common number(s) found...");
}
}






private static void printArray(int[] array)
{
System.out.println();
for (int i = 0; i < array.length; i++)
{
if (array[i] < 10)
System.out.print(" ");
System.out.print(array[i] + " ");

if ((i+1) % 20 == 0)
System.out.println();
}


}





private static int[] a;
public static int[] sort(int[] array)
{
a = array;
sort(0, a.length - 1);
return a;
}

public static void sort(int low, int high)
{
if (low >= high)
return;
int p = partition(low, high);
sort (low, p);
sort (p+1, high);
}

public static int partition(int low, int high)
{
int pivot = a[low];

int i = low - 1;
int j = high + 1;

while (i < j)
{
for (i++; a[i] < pivot; i++);
for (j--; a[j] > pivot; j--);
if (i < j)
swap(i, j);
}
return j;
}

public static void swap(int i, int j)
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}




public static boolean search(int a[], int x)
{

boolean found = false;
for(int i=0; i<a.length; i++)
if(a[i]==x)
{
found=true;
break;
}
return found;
}

public static int[] common(int a[], int b[])
{
Vector v = new Vector();

for(int i=0; i<a.length; i++)
if(search(b, a[i]))
v.add(a[i]);

int[] c=new int[v.size()];
for(int i=0; i<c.length; i++)
c[i] =((Integer) v.elementAt(i)).intValue();

return c;

}




public static int[] select(int a[], int x, int y)
{
int count = 0;
for(int i=0; i<a.length; i++)
if(a[i]>=x && a[i]<=y)
count++;

int [] b;
if(count!=0)
{
b = new int[count];
int j = 0;
for(int i=0; i<a.length; i++)
if(a[i]>=x && a[i]<=y)
b[j++]=a[i];
}
else
b = null;

return b;

}






}





i want to implement arr1 and arr2 in threads. theses threads will list the random numbers. after that thread 3 will take the values from both and sort them

please help..
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
data from the main/GUI thread to another runnin thread... cornercuttin Threads and Synchronization 2 04-24-2008 12:30 AM
If JNI thread call the java object in another thread, it will crash. skaterxu Advanced Java 0 01-28-2008 09:02 AM
Unable to compile gapper New To Java 2 01-14-2008 06:31 PM
Not able to compile bugger New To Java 2 01-10-2008 12:13 AM
Creating a Thread (extending Java Thread Class) JavaForums Java Blogs 0 12-19-2007 11:31 AM


All times are GMT +3. The time now is 08:17 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org