01/10/2018, 17:39

Viết chương trình sử dụng stack trong việc khử đệ quy thuật toán QuickSort bị lỗi ở vòng while

Anh chị giúp e về stack với ạ. nó cứ bị lỗi không chạy được bài. báo lỗi ở while ạ. Viết chương trình sử dụng stack trong việc khử đệ quy thuật toán QuickSort

import java.util.Scanner;
import java.util.Stack;

public class khuDeQuy {
int a[];
int n;
public int[] getA() {
	return a;
}
public void setA(int[] a) {
	this.a = a;
}
public int getN() {
	return n;
}
public void setN(int n) {
	this.n = n;
}
public khuDeQuy(int[] a, int n) {
	this.a = a;
	this.n = n;
}
public khuDeQuy() {
	super();
	// TODO Auto-generated constructor stub
	this.n=0;
}
public void nhap()
{
	System.out.println("nhap mang: ");
	Scanner scan=new Scanner(System.in);
	for(int i=0;i<n;i++)
	{
		System.out.println("a["+i+"]=");
		a[i]=scan.nextInt();
	}
}
public void xuat()
{
	System.out.println("xuat mang: ");
	for(int i=0;i<n;i++)
	{
		System.out.println(a[i]+" ");
	}
}
public void QuickSort(int Left, int Right)
{
	Stack<HongTham>st=new Stack<HongTham>();
	HongTham k= new HongTham(Left,Right);
			st.push(k);
	while(st.empty()==false)
	{
		HongTham x=st.pop();
		int L=x.getDau();
		int R=x.getCuoi();
		int i=L;
		int j=R;
		int mid=(L+R)/2;
	do {
		while(L<a[mid])/////
			i++;
		while(R>a[mid])
			j--;
		if(i<=j)
		{
			int t=a[L];
			a[L]=a[R];
			a[R]=t;
			i++;
			j--;
		}
	if(i>mid&&j<mid)
		break;
			
	}while(i<j);
	if(i<R)st.push(new HongTham(i,R));
	if(L<j)st.push(new HongTham(L,j));
	
	}
}
}
Bài liên quan
0