Pages

Tuesday, April 1, 2014

Java code for Bubble Sort Selection Sort Insertion Sort and Quick Sort

/*
Program to sort an array, entered by the user, in ascending order
using Bubble Sort, Selection Sort, Insertion Sort or Quick Sort as
per users choice.
*/

import java.io.*;
class sortArray
{
int a[];
int n;
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
public sortArray(int nn) // Constructor
{
a = new int[nn];
n = nn;
}
public static void main(String args[]) throws IOException
{
System.out.print("
Enter the size of the array : ");
int nn = Integer.parseInt(br.readLine());
sortArray call = new sortArray(nn);
// Read array from user
System.out.println("
Enter " +nn +" elements :");
call.readArray();
// Ask for choosing the sorting technique
System.out.println("Choose Sorting Technique :
");
System.out.println("1 : Bubble Sort");
System.out.println("2 : Selection Sort");
System.out.println("3 : Insertion Sort");
System.out.println("4 : Quick Sort");
System.out.print("
Your Choice : ");
int choice = Integer.parseInt(br.readLine());
switch(choice)
{
case 1:
call.bubbleSort();
break;
case 2:
call.selectionSort();
break;
case 3:
call.insertionSort();
break;
case 4:
call.quickSort();
break;
default :
System.out.println("
Invalid Choice !");
System.exit(1);
break;
}
call.display(); // Print the sorted array
}
public void readArray() throws IOException
{
for(int i=0;i<n;i++)
a[i] = Integer.parseInt(br.readLine());
}
public void bubbleSort()
{
int t;
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
}
public void selectionSort()
{
int t, min;
for(int i=0;i<n-1;i++)
{
min = i;
for(int j=i+1;j<n;j++)
2{
if(a[min]>a[j])
min = j;
}
if(min!=i)
{
t = a[min];
a[min] = a[i];
a[i] = t;
}
}
}
public void insertionSort()
{
int t,j;
for(int i=1;i<n;i++)
{
j = i-1;
t = a[i];
while(t<a[j] && j>=0)
{
a[j+1] = a[j];
j--;
}
a[j+1] = t;
}
}
public void quickSort()
{
int t;
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
}
public void display()
{
System.out.println("
Sorted Array :");
for(int i=0;i<n;i++)
System.out.println(a[i]);
3}
}

/**
* Algorithm for Selection Sort :
* ----------------------------
* 1. Start
* 2. Construct a single-dimensional array of appropriate size.
* 3. Fill the array with data entries.
* 4. Using selection sort technique bring the smallest number to the
first unsorted position of the array.
* 5. Repeat step 4 till the entire array is sorted.
* 6. Print the sorted array.
* 7. End
*
* Algorithm for Bubble Sort :
* ----------------------------
* 1. Start
* 2. Construct a single-dimensional array of appropriate size.
* 3. Fill the array with data entries.
* 4. Using bubble sort technique push the largest number to the last
unsorted position of the array.
* 5. Repeat step 4 till the entire array is sorted.
* 6. Print the sorted array.
* 7. End
*
* Algorithm for Insertion Sort :
* ----------------------------
* 1. Start
* 2. Construct a single-dimensional array of appropriate size.
* 3. Fill the array with data entries.
* 4. Using insertion sort technique push the largest number to the
last unsorted position of the array.
* 5. Repeat step 4 till the entire array is sorted.
* 6. Print the sorted array.
* 7. End
*
* Algorithm for Quick Sort :
* ----------------------------
* 1. Start
* 2. Construct a single-dimensional array of appropriate size.
* 3. Fill the array with data entries.
* 4. Using quick sort technique push the largest number to the last
unsorted position of the array.
* 5. Repeat step 4 till the entire array is sorted.
* 6. Print the sorted array.
* 7. End
*/

/*
OUTPUT :
------
Enter the size of the array : 5
Enter 5 elements :
12
54
65
32
23
Choose Sorting Technique :
1
2
3
4
:
:
:
:
Bubble Sort
Selection Sort
Insertion Sort
Quick Sort
Your Choice : 1
Sorted Array :
12
23
32
54
65
*/


Read More..

C code to find Power Set of given numbers

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define ROW 8
#define COL 256
void main()
{
  int i,j,k,num,temp,flag;
  int table[COL][ROW]={0};
  char set[ROW][20];
  clrscr();
  printf("
Enter the number of set elements: ");
  scanf("%d",&num);
  printf("
Enter any %d elements:
",num);
  for(i=0;i<num;i++)
  {  
    fflush(stdin);
    gets(set[i]);
   
  }
  for(i=0;i<pow(2,num);i++)
  {
    temp=i;
    for(j=0;j<num;j++)
    {
      table[i][j]=temp%2;
      temp=temp/2;
    }
  }
  printf("
The power set is:

");
  for(i=0;i<pow(2,num);i++)
  {
    printf("

{");
    for(j=0;j<num;j++)
    {
      flag=0;
      if(table[i][j]==1)
      {
    for(k=j+1;k<num;k++)
      if(table[i][k]==1)
        flag=1;
    if(flag==1)
      printf(" %s ,",set[j]);
    else
      printf(" %s  ",set[j]);
      }
    }
    printf("}");
  }
  getch();

}


Read More..

Monday, March 31, 2014

Search address by name with Geocoder

The getFromLocationName() method of android.location.Geocoder returns an array of Addresses that are known to describe the named location.

Example of searching address by name with Geocoder:

Search address by name with Geocoder


package com.example.androidgeocoder;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

EditText searchIn;
Button searchButton;
ListView searchOut;

private ArrayAdapter<String> adapter;

Geocoder geocoder;
final static int maxResults = 5;
List<Address> locationList;
List<String> locationNameList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchIn = (EditText)findViewById(R.id.serchin);
searchButton = (Button)findViewById(R.id.serch);
searchOut = (ListView)findViewById(R.id.serchout);

searchButton.setOnClickListener(searchButtonOnClickListener);

geocoder = new Geocoder(this, Locale.ENGLISH);

locationNameList = new ArrayList<String>(); //empty in start
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, locationNameList);
searchOut.setAdapter(adapter);
}

OnClickListener searchButtonOnClickListener =
new OnClickListener(){

@Override
public void onClick(View arg0) {
String locationName = searchIn.getText().toString();

Toast.makeText(getApplicationContext(),
"Search for: " + locationName,
Toast.LENGTH_SHORT).show();

if(locationName == null){
Toast.makeText(getApplicationContext(),
"locationName == null",
Toast.LENGTH_LONG).show();
}else{
try {
locationList = geocoder.getFromLocationName(locationName, maxResults);

if(locationList == null){
Toast.makeText(getApplicationContext(),
"locationList == null",
Toast.LENGTH_LONG).show();
}else{
if(locationList.isEmpty()){
Toast.makeText(getApplicationContext(),
"locationList is empty",
Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(),
"number of result: " + locationList.size(),
Toast.LENGTH_LONG).show();

locationNameList.clear();

for(Address i : locationList){
if(i.getFeatureName() == null){
locationNameList.add("unknown");
}else{
locationNameList.add(i.getFeatureName());
}
}

adapter.notifyDataSetChanged();
}
}


} catch (IOException e) {
Toast.makeText(getApplicationContext(),
"network unavailable or any other I/O problem occurs" + locationName,
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}};

}


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/serchin"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/serch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Search" />
<ListView
android:id="@+id/serchout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>


download filesDownload the files.

Read More..

Sunday, March 30, 2014

Example of ViewFlipper

android.widget.ViewFlipper is a simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.

Example of ViewFlipper

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<Button
android:id="@+id/prev"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="previous" />

<Button
android:id="@+id/next"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="next" />
</LinearLayout>

<ViewFlipper
android:id="@+id/viewflipper"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="- Button 2 -" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LinearLayout 2" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter something" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LinearLayout 3" />
</LinearLayout>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ViewFlipper is a simple ViewAnimator that
will animate between two or more views that
have been added to it. Only one child is shown
at a time. If requested, can automatically
flip between each child at a regular interval." />
</ViewFlipper>

</LinearLayout>

package com.example.androidviewflipper;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewFlipper;

public class MainActivity extends Activity {

Button buttonPrev, buttonNext;
ViewFlipper viewFlipper;

Animation slide_in_left, slide_out_right;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

buttonPrev = (Button) findViewById(R.id.prev);
buttonNext = (Button) findViewById(R.id.next);
viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);

slide_in_left = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
slide_out_right = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);

viewFlipper.setInAnimation(slide_in_left);
viewFlipper.setOutAnimation(slide_out_right);

buttonPrev.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
viewFlipper.showPrevious();
}
});

buttonNext.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
viewFlipper.showNext();
}
});
;
}

}

Read More..

Saturday, March 29, 2014

UPDATE NOW! Oracle JDK 7u11 released



Oracle releasdd JDK 7u11 to answer the the flaw in Java software integrated with web browsers.

This release contains fixes for security vulnerabilities. For more information, see Oracle Security Alert for CVE-2013-0422.

Java SE 7 Update 11 is available from the following download sites:


Read More..

Wednesday, March 26, 2014

The Lost Souls v1 0 1 1 Apk Full Version

The Lost Souls v1.0.1.1 Apk Full Version

The Lost Souls v1.0.1.1 APK FULL VERSION
Req: Android 2.1+ Android Apk Free


The Lost Souls v1.0.1.1 APK fully new version! The Lost Souls is a “Escape the Room” game style, with HIGH QUALITY GRAPHICS, many scary scenes and some puzzles to Solve. ..NOW IN ANDROID!

NOTE:
The Lost Souls v1.0.1.1 Apk Full Version contains strong images, scary scenes and gore.
You’ll be playing at your own risk .

TNX and injoy

Download The Lost Souls v1.0.1.1 Apk Full Version
Read More..

Tuesday, March 25, 2014

Gravity Home Pro 1 3 Full APK


Gravity Home Pro 1.3 Full APK. transform your residence screen utilizing a funny various launcher ! gravity home = live wallpaper + launcher + physics flip the phone upside down and watch your favorite app icons respond out to gravity, hanging aroung the screen, being completelly funcional.



Read More..