Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34070
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-04-06 14:17 -0700 |
| References | <7b9b4702-130f-4533-8c3c-3d39c1fd9f6a@googlegroups.com> |
| Message-ID | <eeaad8b0-69c9-4149-b73d-4e26aed00e3c@googlegroups.com> (permalink) |
| Subject | Re: pendulum program -7 number input not working |
| From | parthmadhani9@gmail.com |
On Tuesday, January 26, 2016 at 10:46:01 PM UTC+5:30, puj...@gmail.com wrote:
> for(int i=0;i<n;i++)
> {if(i%2==0)
> mid=n/2-l;
> else
> mid=n/2+l;
> min=a[mid];
make it n-1
import java.util.*;
class Pendulum_Sorting
{public static void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the elements of the array");
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
int mid=0,min=0,l=0,pos=0;
for(int i=0;i<n-1;i++)
{
if(i%2==0)
mid=(n/2-l);
else
mid=(n/2+l);
min=a[mid];
for(int j=0;j<n;j++)
{if(i%2==0)
{if((j>=mid)&&(j<=(mid+(l*2))))
continue;
}
else
{if((j<=mid)&&(j>=(mid-(l*2)+1)))
continue;
}
if(a[j]<min)
{min=a[j];
pos=j;
}
}
a[pos]=a[mid];
a[mid]=min;
if(i%2==0)
l++;
}
for(int i=0;i<n;i++)
System.out.print(a[i]+" ");
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
pendulum program -7 number input not working puja219@gmail.com - 2016-01-26 09:15 -0800
Re: pendulum program -7 number input not working Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-01-26 13:11 -0500
Re: pendulum program -7 number input not working Jeff Higgins <jeff@invalid.invalid> - 2016-01-27 02:05 +0000
Re: pendulum program -7 number input not working Jeff Higgins <jeff@invalid.invalid> - 2016-01-27 02:11 +0000
Re: pendulum program -7 number input not working Arne Vajhøj <arne@vajhoej.dk> - 2016-01-26 21:39 -0500
Re: pendulum program -7 number input not working Lew <lewbloch@gmail.com> - 2016-01-27 15:08 -0800
Re: pendulum program -7 number input not working parthmadhani9@gmail.com - 2016-04-06 14:17 -0700
csiph-web