-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47cabdc
commit 0c98679
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.mycompany.noor; | ||
import java.util.Scanner; | ||
public class array_bubble_char | ||
{//ascending | ||
void bubblesort() | ||
{ | ||
char c[],temp; | ||
int i,j,n; | ||
Scanner sc=new Scanner(System.in); | ||
System.out.println("Enter number of elements"); | ||
n=sc.nextInt(); | ||
c=new char[n]; | ||
System.out.println("Enter "+n+" characters"); | ||
for(i=0;i<n;i++) | ||
{ | ||
c[i]=sc.next().charAt(0); | ||
} | ||
for(i=0;i<n;i++) | ||
{ | ||
for(j=0;j<(n-1);j++) | ||
{ | ||
if(c[j]>c[j+1]) | ||
{ | ||
temp=c[j]; | ||
c[j]=c[j+1]; | ||
c[j+1]=temp; | ||
} | ||
} | ||
} | ||
for(i=0;i<n;i++) | ||
System.out.print(c[i]+" "); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
array_bubble_char obj=new array_bubble_char(); | ||
obj.bubblesort(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.mycompany.noor; | ||
import java.util.Scanner; | ||
public class array_bubble_int | ||
{//ascending | ||
void bubblesort() | ||
{ | ||
int arr[]; | ||
int i,j,n,temp; | ||
Scanner sc=new Scanner(System.in); | ||
System.out.println("Enter number of elements"); | ||
n=sc.nextInt(); | ||
arr=new int[n]; | ||
System.out.println("enter "+n+" numbers"); | ||
for(i=0;i<n;i++) | ||
{ | ||
arr[i]=sc.nextInt(); | ||
} | ||
for(i=0;i<n;i++) | ||
{ | ||
for(j=0;j<(n-1);j++) | ||
{ | ||
if(arr[j]>arr[j+1]) | ||
{ | ||
temp=arr[j]; | ||
arr[j]=arr[j+1]; | ||
arr[j+1]=temp; | ||
} | ||
} | ||
} | ||
for(i=0;i<n;i++) | ||
System.out.print(arr[i]+" "); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
array_bubble_int obj=new array_bubble_int(); | ||
obj.bubblesort(); | ||
} | ||
} |