Thursday, August 25, 2011

quick sorting

public class QuickSortSimpleVersion {
private long[] data;

private int len;

public QuickSortSimpleVersion(int max) {
data = new long[max];
len = 0;
}

public void insert(long value) {
data[len] = value;
len++;
}

public void display() {
System.out.print("Data");
for (int j = 0; j < len; j++)
System.out.print(data[j] + " ");
System.out.println("");
}

public void quickSort() {
recQuickSort(0, len - 1);
}

public void recQuickSort(int left, int right) {
if (right - left <= 0) // if size <= 1 already sorted
return;
else // size is 2 or larger
{
long pivot = data[right]; // rightmost item
// partition range
int partition = partitionData(left, right, pivot);
recQuickSort(left, partition - 1); // sort left side
recQuickSort(partition + 1, right); // sort right side
}
}

public int partitionData(int left, int right, long pivot) {
int leftPtr = left - 1; // left (after ++)
int rightPtr = right; // right-1 (after --)
while (true) { // find bigger item
while (data[++leftPtr] < pivot)
;
// find smaller item
while (rightPtr > 0 && data[--rightPtr] > pivot)
;

if (leftPtr >= rightPtr) // if pointers cross, partition done
break;
else
swap(leftPtr, rightPtr);
}
swap(leftPtr, right); // restore pivot and return pivot location
return leftPtr;
}

public void swap(int d1, int d2) {
long temp = data[d1];
data[d1] = data[d2];
data[d2] = temp;
}

public static void main(String[] args) {
int maxSize = 16; // array size
QuickSortSimpleVersion arr = new QuickSortSimpleVersion(maxSize); // create array

for (int j = 0; j < maxSize; j++) // fill array with random numbers
{
long n = (int) (java.lang.Math.random() * 99);
arr.insert(n);
}
arr.display();
arr.quickSort();
arr.display();
}

}

merge sort

public class InsertionSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println("\n\n RoseIndia\n\n");
System.out.println(" Selection Sort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
System.out.println();
insertion_srt(array, array.length);
System.out.print("Values after the sort:\n");
for(i = 0; i )
System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}

public static void insertion_srt(int array[], int n){
for (int i = 1; i < n; i++){
int j = i;
int B = array[i];
while ((j > 0) && (array[j-1] > B)){
array[j] = array[j-1];
j--;
}
array[j] = B;
}
}
}

fibanocci program

class Fibonacci

{

public static void main(String args[]){

int num = 5; //taking no. as command line argument.

System.out.println("*****Fibonacci Series*****");
int f1, f2=0, f3=1;
for(int i=1;i<=num;i++){
System.out.print(" "+f3+" ");
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
}

Tuesday, August 23, 2011

amstrong number

#include
#include
void main()
{
int n,r,t,sum=0;
clrscr();
printf(" OUTPUT :\n");
printf("\tEnter a no.");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==t)
printf("The no. %d is armstrong",t);
else
printf("The no. %d is not an armstrong",t);
getch();
}

Sunday, August 21, 2011

given number converted into words

#include

void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};


void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}


void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}

amstrong number

void main() { int n,b=0,t; clrscr(); printf(“Enter the no”); scanf(“%d”,&n); t=n; while(n>0) { a=n%10; b=b+a*a*a; n=n/10; } if(b==t) { printf(“Armstrong no”); } else { printf(“Not an Armstrong no”); } getch(); }

flames program in java

import java.util.*; import java.io.*; import java.lang.*;  public class heh { private static BufferedReader stdin =  new BufferedReader( new InputStreamReader( System.in )); public static void main(String args[])  { BufferedReader object=new BufferedReader(new InputStreamReader(System.in)); int i; int z=0; int x; int[] f={1,7,13,19,25};         int[] l={2,8,14,20,26};         int[] a={3,9,15,21,27};         int[] m={4,10,16,22,28};         int[] e={5,11,17,23,29};         int[] s={6,12,18,24,30}; Scanner in = new Scanner(System.in); System.out.println("Enter the girls name: "); String girlN = in.nextLine(); char[] girlD = girlN.toCharArray(); int glen = girlD.length; System.out.println("Enter the boys name: "); String boyN = in.nextLine(); char[] boyD = boyN.toCharArray(); int blen = boyD.length;  for(x=0;x

connection establishment in php


email

= 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

email send with php

// mehrere Empfänger
$empfaenger = 'max@example.com' . ', '; // beachten Sie das Komma
$empfaenger .= 'moritz@example.com';

// Betreff
$betreff = 'Geburtstags-Erinnerungen für August';

// Nachricht
$nachricht = '


Geburtstags-Erinnerungen für August


Hier sind die Geburtstage im August:












PersonTagMonatJahr
Julia3.August1970
Tom17.August1973



'
;

// für HTML-E-Mails muss der 'Content-type'-Header gesetzt werden
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// zusätzliche Header
$header .= 'To: Simone , Andreas ' . "\r\n";
$header .= 'From: Geburtstags-Erinnerungen ' . "\r\n";
$header .= 'Cc: geburtstagsarchiv@example.com' . "\r\n";
$header .= 'Bcc: geburtstagscheck@example.com' . "\r\n";

// verschicke die E-Mail
mail($empfaenger, $betreff, $nachricht, $header);
?>

Wednesday, August 17, 2011

with out using string function create palindrome in php





Untitled Document





The Reversed String is ".$str1."
";
echo "
".$pal;
}
?>










Enter a text: