Thursday 27 February 2014

/* tbt */

#include <stdio.h>
#include <alloc.h>

enum boolean {
false = 0,
true = 1
};

typedef struct node {
enum boolean isleft;
struct thtree *left;
int data;
struct thtree *right;
enum boolen isright;
}thtree;


void insert (thtree **, int);
void del (thtree **, int);
void search (thtree **, int, thtree **, thtree **, int *);
void inorder (thtree *);
void deltree (thtree **);


void main()
{
int ch;
char *ch_temp;
if (!(ch = malloc(TEMP))) {
printf("\nError in memory allocation\n");
exit(FAILURE);
}
while(1) {
get(ch_temp);
if (isno(ch_temp) == SUCCESS) {
printf("\nInvalid input\n");
continue;
}
if (choice(ch) == SUCCESS)
break;
}
FREE(ch_temp);
return SUCCESS;
}


/* Get choice from user */

int choice(int ch)
{
char *temp;
thtree *th_head;
th_head = NULL;

if (!(temp = malloc( TEMP)) {
printf("\nError in memory allocation\n");
exit(FAILURE);
}

switch(ch) {
case 1:
printf("\nEnter the element to insert\n");
while (1) {
get(temp);
if ((isno(temp) == SUCCESS) || ((item = stono(temp)) == MAX))
printf("\nInvalid input\n");
else
break;
}

insert (&th_head, item);
break;
case 2 :
printf("\nEnter the element to delete\n");
while (1) {
get(temp);
if ((isno(temp) == SUCCESS) || ((item = stono(temp)) == MAX))
printf("\nInvalid input\n");
else
break;
}

del (&th_head, item);
break;
case 3 :
display(th_head);
break;
case 4 :
FREE (th_head);
return SUCCESS;
default :
printf("\nInvalid input\n\n");
}
return FAILURE;
}


/* insert a node in threaded binary tree */

void insert (thtree **s, int num)
{
thtree *p, *z, *head = *s ;

if (!(z = malloc(TBT))) {
printf("\nError in allocating memory for node");
return;
}

z -> isleft = true;
z -> data = num;
z -> isright = true;

if (*s == NULL) {
if (!(head = malloc(TBT))) {
printf("\nError in allocating memory for node");
return;
}

        /* the entire tree is treated as a left sub-tree of the head node */

head -> isleft = false;
head -> left = z;
head -> data = -9999;
head -> right = head;
head -> isright = false;
*s = head;
z -> left = head;
z -> right = head;
} else {
p = head -> left;
        /* traverse till the thread is found attached to the head */

while (p != head) {
if (p -> data > num) {
if (p -> isleft != true)
p = p -> left;
else {
z -> left = p -> left;
p -> left = z;
p -> isleft = false;
z -> isright = true;
z -> right = p;
}
}
else if (p -> data < num) {
if (p -> isright != true)
p = p -> right;
else {
z -> right = p -> right;
p -> right = z;
p -> isright = false;
z -> isleft = true;
z -> left = p;
}
}
else if (p -> data == num) {
printf("\nData duplication. Insertion failed.\n");
return;
}
}
}
printf("\nNode inserted\n\n");
}


/* delete a node from threaded binary tree */
void del(thtree **root, int num)
{
int found;
thtree *parent, *x, *xsucc;

    /* if tree is empty */
if (*root == NULL) {
printf("\nTree is empty");
return;
}

parent = x = NULL;

search(root, num, &parent, &x, &found);

if (found == false) {
printf("\nData not found\n");
return;
}

/* if the node to be deleted has two children */

if ((x -> isleft == false) && (x -> isright == false)) {
parent = x;
xsucc = x -> right;
while (xsucc -> isleft == false) {
parent = xsucc;
xsucc = xsucc -> left;
}
x -> data = xsucc -> data;
x = xsucc;
}

/* if the node to be deleted has no child */

if ((x -> isleft == true) && (x -> isright == true)) {
       /* if node to be deleted is a root node */
if (parent == NULL) {
(*root) -> left = *root;
(*root) -> isleft = true;
FREE(x);
return;
}

if ( parent -> right == x ) {
parent -> isright = true;
parent -> right = x -> right;
} else {
parent -> isleft = true;
parent -> left = x -> left;
}
FREE(x);
return;
}

/* if the node to be deleted has only rightchild */

if ((x -> isleft == true) && (x -> isright == false)) {
/* node to be deleted is a root node */
if (parent == NULL) {
(*root) -> left = x -> right;
FREE(x);
return;
}

if (parent -> left == x) {
parent -> left = x -> right;
x -> right -> left = x -> left;
} else {
parent -> right = x -> right;
x -> right -> left = parent;
}
FREE(x);
return;
}

/* if the node to be deleted has only left child */

if ((x -> isleft == false) && (x -> isright == true)) {
/* the node to be deleted is a root node */
if (parent == NULL) {
parent = x;
xsucc = x -> left;
while (xsucc -> right == false)
xsucc = xsucc -> right;

xsucc -> right = *root;
(*root) -> left = x -> left;
FREE(x);
return;
}

if (parent -> left == x) {
parent -> left = x -> left;
x -> left -> right = parent;
} else {
parent -> right = x -> left;
x -> left -> right = x -> right;
}
FREE(x);
return;
}
}

/* returns address of node to be deleted, address of its parent and
    whether the node is found or not */

void search(thtree **root, int num, thtree **par, thtree **x, int *found)
{
thtree *q;

q = (*root) -> left;
*found = false;
*par = NULL;

while (q != *root) {
/* if the node to be deleted is found */
if (q -> data == num) {
*found = true;
*x = q;
return;
}

*par = q;
if (q -> data > num) {
if (q -> isleft == true) {
*found = false;
x = NULL;
return;
}
q = q -> left;
} else {
if (q -> isright == true) {
*found = false;
*x = NULL;
return;
}
q = q -> right;
}
}
}


/* traverses the threaded binary tree in inorder */
void inorder(thtree *root)
{
thtree *p;
p = root -> left;

while (p != root) {
while (p -> isleft == false)
p = p -> left;
printf ("%d\t", p -> data);

while (p -> isright == true) {
p = p -> right;
if (p == root)
break;
printf("%d\t", p -> data);
}
p = p -> right;
}
}


Wednesday 26 February 2014

http://gallery.mobile9.com/f/1622268/?ref=3816

http://gallery.mobile9.com/f/2822748/?ref=3816

http://gallery.mobile9.com/f/2783739/?ref=3816

http://gallery.mobile9.com/f/2518705/?ref=3816

http://gallery.mobile9.com/f/2638433/?ref=3816

Make sure to read the hint, before installing. Don't Loose Opportunity for Using This Magnificent Player. What’s new in this one: $$* Fixed bug of ID3 tags reading (Please clean playlist then re-scan songs) $$* Reduced start-up time $$* Solved problem of auto playback after calls $$* Fixed alarm problem on S^3 devices $$* Personal Support Center, QQ mini-player on desktop Features:- ¥#. Full support for S^3 and S60v5 devices ¥#. Special interface for control using touch screen ¥#. Supported formats: MP3, AAC, WMA and M4A ¥#. Built-in equalizer, which is CUSTOMISABLE ¥#. Sound fade, stereo widening and bass boost effects ¥#. Support for skins and visual effects ¥#. Ability to download song's album covers and lyrics, and you can view lyrics while the song is playing ;-) ¥#. Online access to music charts ¥#. Sleep timer ¥#. Mini-player in background mode and many more features… HINT:- In some Mobile Models you need to install a Patch for TTpod to run it. Dont worry dudes. Here i have uploaded a '.zip' file which contains 2 files 1. TTPod Extreme v4.31 & 2. TTPod Extreme v4.31 Patch VERY VERY IMPORTANT: After downloading, 'RENAME' it from ".sis" to ".zip" Then 'UNZIP' it by using either xplore, idecompress, unzip or fexplorer. Now you have got 2 unsigned .sis files. Then just 'SIGN' both of them with your own certificate and key using freesigner. Then 'INSTALL BOTH FILES' in your device. NOW ENJOY THE FANTASTIC WORLD OF MUSIC, HAVE FUN & ENJOY.........!.;-) Please dont forget to RATE it and ADD TO YOUR FAVOURITES. HOPE YOU ALL LIKE IT ;-)

http://gallery.mobile9.com/f/2029727/?ref=3816


TTPod v4.10 Beta english S60v5 S60v3 

New Version Feature: 
1=>> the new touch-screen interface design,better operating experience ;
2 =>>the new image decoding program to suport all formats built-in image display ;
3=>> support one hundred adjust the volume , the sound is more delicate ;
4=>> the icon style menu , the operation more convenient ;
5=>> swinging your mobile phone,easily switch between songs ;
6=>> by adding pull out the headphone spause , press side buttons and the repesonalized features of the song ;
7=>> increasing feed back and word graph error function ;
8=>> the splash screens up port for jpg images ;
9=>> increasing Symbian ^3 platform support models .
 
Always the new in my gallery...enjoy this wonderfull player..if you like it pls hit rate & add it to your favorites..thanks in advance.


patch :

http://gallery.mobile9.com/f/3382593/

ttpod lite :
http://gallery.mobile9.com/f/2304306/

Saturday 22 February 2014

/* radix */

#include<stdio.h>

radix_sort(int array[], int n);
int main()
{
 int array[100],n,i;
 printf("Enter the number of elements to be sorted: ");
 scanf("%d",&n);
 printf("\nEnter the elements to be sorted: \n");
 for(i = 0 ; i < n ; i++ )
 {
  printf("\tArray[%d] = ",i);
  scanf("%d",&array[i]);
 }
 
 printf("\nArray Before Radix Sort:"); 
 for(i = 0; i < n; i++)
 {
  printf("%8d", array[i]);
 }
 printf("\n");
 
 radix_sort(array,n);

 printf("\nArray After Radix Sort: "); 
 for(i = 0; i < n; i++)
 {
  printf("%8d", array[i]);
 }
 printf("\n");
}

radix_sort(int arr[], int n)
{
 int bucket[10][5],buck[10],b[10];
 int i,j,k,l,num,div,large,passes;
 
 div=1;
 num=0;
 large=arr[0];
 
 for(i=0 ; i<n ; i++)
 {
  if(arr[i] > large)
   {
    large = arr[i];
   }
   
  while(large > 0)
  {
   num++;
   large = large/10;
  }
  
  for(passes=0 ; passes<num ; passes++)
  {
   for(k=0 ; k<10 ; k++)
   {
    buck[k] = 0;
   }
   for(i=0 ; i<n  ;i++)
   {
    l = ((arr[i]/div)%10);
    bucket[l][buck[l]++] = arr[i];
   }
   
   i=0;
   for(k=0 ; k<10 ; k++)
   {
    for(j=0 ; j<buck[k] ; j++)
    {
     arr[i++] = bucket[k][j];
    }
   }  
   div*=10;  
  }
 }


/* radix */

#include <stdio.h>
// A utility function to get maximum value in arr[]
int getMax(int arr[], int n)
{
    int mx = arr[0];
    for (int i = 1; i < n; i++)
        if (arr[i] > mx)
            mx = arr[i];
    return mx;
}

// A function to do counting sort of arr[] according to
// the digit represented by exp.
void countSort(int arr[], int n, int exp)
{
    int output[n]; // output array
    int i, count[10] = {0};

    // Store count of occurrences in count[]
    for (i = 0; i < n; i++)
        count[ (arr[i]/exp)%10 ]++;

    // Change count[i] so that count[i] now contains actual position of
    // this digit in output[]
    for (i = 1; i < 10; i++)
        count[i] += count[i - 1];

    // Build the output array
    for (i = n - 1; i >= 0; i--)
    {
        output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
        count[ (arr[i]/exp)%10 ]--;
    }

    // Copy the output array to arr[], so that arr[] now
    // contains sorted numbers according to curent digit
    for (i = 0; i < n; i++)
        arr[i] = output[i];
}

// The main function to that sorts arr[] of size n using Radix Sort
void radixsort(int arr[], int n)
{
    // Find the maximum number to know number of digits
    int m = getMax(arr, n);

    // Do counting sort for every digit. Note that instead of passing digit number,
    // exp is passed. exp is 10^i where i is current digit number
    for (int exp = 1; m/exp > 0; exp *= 10)
        countSort(arr, n, exp);
}

// A utility function to print an array
void print(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
}

// Driver program to test above functions
int main()
{
    int arr[] = {170, 45, 75, 90, 802, 24, 2, 66};
    int n = sizeof(arr)/sizeof(arr[0]);
    radixsort(arr, n);
    print(arr, n);
    return 0;
}
}


/* bucket */


#include<stdio.h>
void Bucket_Sort(int array[], int n)
{  
 int i, j;  
 int count[n]; 
 for(i=0; i < n; i++)
 {  
  count[i] = 0;  
 }    
 for(i=0; i < n; i++)
 {   
  (count[array[i]])++;
 }    
 for(i=0,j=0; i < n; i++)
 {  
  for(; count[i]>0;(count[i])--)
  {      
   array[j++] = i;
  } 
 }  
}   
int main()
{
 int array[100];  
 int num;  
 int i; 
 printf("Enter How many Numbers : ");   
 scanf("%d",&num);   
 printf("Enter the %d elements to be sorted:\n",num); 
 for(i = 0; i < num; i++ )
 {  
  scanf("%d",&array[i]); 
 }  
 printf("\nThe array of elements before sorting : \n");
 for (i = 0;i < num;i++)
 {   
  printf("%d ", array[i]);  
 }   
 printf("\nThe array of elements after sorting : \n"); 
 Bucket_Sort(array, num); 
 for (i = 0;i < n;i++)
 {    
  printf("%d ", array[i]); 
 }  
 printf("\n");     
 return 0;
}


/* priority queue */

    #include<stdio.h>
    #include<stdlib.h>

    struct node
    {
    int priority;
    int info;
    struct node *link;
    }*front=NULL;

    void insert(int item, int item_priority);
    int del();
    void display();
    int isEmpty();

    main()
    {
    int choice,item,item_priority;
    while(1)
    {
    printf(“1.Insert\n”);
    printf(“2.Delete\n”);
    printf(“3.Display\n”);
    printf(“4.Quit\n”);
    printf(“Enter your choice : “);
    scanf(“%d”, &choice);

    switch(choice)
    {
    case 1:
    printf(“Input the item to be added in the queue : “);
    scanf(“%d”,&item);
    printf(“Enter its priority : “);
    scanf(“%d”,&item_priority);
    insert(item, item_priority);
    break;
    case 2:
    printf(“Deleted item is %d\n”,del());
    break;
    case 3:
    display();
    break;
    case 4:
    exit(1);
    default :
    printf(“Wrong choice\n”);
    }
    }
    }

    void insert(int item,int item_priority)
    {
    struct node *tmp,*p;

    tmp=(struct node *)malloc(sizeof(struct node));
    if(tmp==NULL)
    {
    printf(“Memory not available\n”);
    return;
    }
    tmp->info=item;
    tmp->priority=item_priority;
    if( isEmpty() || item_priority < front->priority )
    {
    tmp->link=front;
    front=tmp;
    }
    else
    {
    p = front;
    while( p->link!=NULL && p->link->priority<=item_priority )
       p=p->link;
    tmp->link=p->link;
    p->link=tmp;
    }
    }

    int del()
    {
    struct node *tmp;
    int item;
    if( isEmpty() )
    {
    printf(“Queue Underflow\n”);
    exit(1);
    }
    else
    {
    tmp=front;
    item=tmp->info;
    front=front->link;
    free(tmp);
    }
    return item;
    }

    int isEmpty()
    {
    if( front == NULL )
    return 1;
    else
    return 0;

    }

    void display()
    {
    struct node *ptr;
    ptr=front;
    if( isEmpty() )
    printf(“Queue is empty\n”);
    else
    {    printf(“Queue is :\n”);
    printf(“Priority       Item\n”);
    while(ptr!=NULL)
    {
    printf(“%5d        %5d\n”,ptr->priority,ptr->info);
    ptr=ptr->link;
    }
    }
    }




/* bst */

void delete1(struct btnode *t)

{

    int k;



    /* To delete leaf node */

    if ((t->l == NULL) && (t->r == NULL))

    {

        if (t1->l == t)

        {

            t1->l = NULL;

        }

        else

        {

            t1->r = NULL;

        }

        t = NULL;

        free(t);

        return;

    }



    /* To delete node having one left hand child */

    else if ((t->r == NULL))

    {

        if (t1 == t)

        {

            root = t->l;

            t1 = root;

        }

        else if (t1->l == t)

        {

            t1->l = t->l;



        }

        else

        {

            t1->r = t->l;

        }

        t = NULL;

        free(t);

        return;

    }



    /* To delete node having right hand child */

    else if (t->l == NULL)

    {

        if (t1 == t)

        {

            root = t->r;

            t1 = root;

        }

        else if (t1->r == t)

            t1->r = t->r;

        else

            t1->l = t->r;

        t == NULL;

        free(t);

        return;

    }



    /* To delete node having two child */

    else if ((t->l != NULL) && (t->r != NULL)) 

    {

        t2 = root;

        if (t->r != NULL)

        {

            k = smallest(t->r);

            flag = 1;

        }

        else

        {

            k =largest(t->l);

            flag = 2;

        }

        search1(root, k);

        t->value = k;

    }



}


/* tbt */

#include <stdio.h>
#include <conio.h>
#include <alloc.h>

enum boolean
{
    false = 0,
    true = 1
} ;

struct thtree
{
    enum boolean isleft ;
    struct thtree *left ;
    int data ;
    struct thtree *right ;
    enum boolen isright ;
} ;

void insert ( struct thtree **, int ) ;
void delete ( struct thtree **, int ) ;
void search ( struct thtree **, int, struct thtree **,
                struct thtree **, int * ) ;
void inorder ( struct thtree * ) ;
void deltree ( struct thtree ** ) ;

void main( )
{
    struct thtree *th_head ;

    th_head = NULL ;  /* empty tree */


    insert ( &th_head, 11 ) ;
    insert ( &th_head, 9 ) ;
    insert ( &th_head, 13 ) ;
    insert ( &th_head, 8 ) ;
    insert ( &th_head, 10 ) ;
    insert ( &th_head, 12 ) ;
    insert ( &th_head, 14 ) ;
    insert ( &th_head, 15 ) ;
    insert ( &th_head, 7 ) ;

    clrscr( ) ;
    printf ( "Threaded binary tree before deletion:\n" ) ;
    inorder ( th_head ) ;

    delete ( &th_head, 10 ) ;
    printf ( "\nThreaded binary tree after deletion:\n" ) ;
    inorder ( th_head ) ;

    delete ( &th_head, 14 ) ;
    printf ( "\nThreaded binary tree after deletion:\n" ) ;
    inorder ( th_head ) ;

    delete ( &th_head, 8 ) ;
    printf ( "\nThreaded binary tree after deletion:\n" ) ;
    inorder ( th_head ) ;

    delete ( &th_head, 13 ) ;
    printf ( "\nThreaded binary tree after deletion:\n" ) ;
    inorder ( th_head ) ;

    deltree ( &th_head ) ;

    getch( ) ;
}

/* inserts a node in a threaded binary tree */
void insert ( struct thtree **s, int num )
{
    struct thtree *p, *z, *head = *s ;

    /* allocating a new node */

    z = malloc ( sizeof ( struct thtree ) ) ;

    z -> isleft = true ;  /* indicates a thread */

    z -> data = num ;  /* assign new data */

    z -> isright = true ;  /* indicates a thread */
/* if tree is empty */
if ( *s == NULL )
    {
        head = malloc ( sizeof ( struct thtree ) ) ;

        /* the entire tree is treated as a left sub-tree of the head node */

        head -> isleft = false ;
        head -> left = z ;  /* z becomes leftchild of the head node */

        head -> data = -9999 ;  /* no data */

        head -> right = head ;  /* right link will always be pointing
                                    to itself */

        head -> isright = false ;

        *s = head ;

        z -> left = head ;  /* left thread to head */

        z -> right = head ;  /* right thread to head */

    }
    else/* if tree is non-empty */

    {
        p = head -> left ;

        /* traverse till the thread is found attached to the head */
while ( p != head )
        {
            if ( p -> data > num )
            {
                if ( p -> isleft != true )  /* checking for a thread */

                    p = p -> left ;
                else
                {
                    z -> left = p -> left ;
                    p -> left = z ;
                    p -> isleft = false ;  /* indicates a link */

                    z -> isright = true ;
                    z -> right = p ;
                    return ;
                }
            }
            else
            {
                if ( p -> data < num )
                {
                    if ( p -> isright != true )
                        p = p -> right ;
                    else
                    {
                        z -> right = p -> right ;
                        p -> right = z ;
                        p -> isright = false ;  /* indicates a link */

                        z -> isleft = true ;
                        z -> left = p ;
                        return ;
                    }
                }
            }
        }
    }
}

/* deletes a node from the binary search tree */
void delete ( struct thtree **root, int num )
{
    int found ;
    struct thtree *parent, *x, *xsucc ;

    /* if tree is empty */
if ( *root == NULL )
    {
        printf ( "\nTree is empty" ) ;
        return ;
    }

    parent = x = NULL ;

    /* call to search function to find the node to be deleted */

    search ( root, num, &parent, &x, &found ) ;

    /* if the node to deleted is not found */
if ( found == false )
    {
        printf ( "\nData to be deleted, not found" ) ;
        return ;
    }

    /* if the node to be deleted has two children */
if ( x -> isleft == false && x -> isright == false )
    {
        parent = x ;
        xsucc = x -> right ;

        while ( xsucc -> isleft == false )
        {
            parent = xsucc ;
            xsucc = xsucc -> left ;
        }

        x -> data = xsucc -> data ;
        x = xsucc ;
    }

    /* if the node to be deleted has no child */
if ( x -> isleft == true && x -> isright == true )
    {
        /* if node to be deleted is a root node */
if ( parent == NULL )
        {
            ( *root ) -> left = *root ;
            ( *root ) -> isleft = true ;

            free ( x ) ;
            return ;
        }

        if ( parent -> right == x )
        {
            parent -> isright = true ;
            parent -> right = x -> right ;
        }
        else
        {
            parent -> isleft = true ;
            parent -> left = x -> left ;
        }

        free ( x ) ;
        return ;
    }

    /* if the node to be deleted has only rightchild */
if ( x -> isleft == true && x -> isright == false )
    {
        /* node to be deleted is a root node */
if ( parent == NULL )
        {
            ( *root ) -> left = x -> right ;
            free ( x ) ;
            return ;
        }

        if ( parent -> left == x )
        {
            parent -> left = x -> right ;
            x -> right -> left = x -> left ;
        }
        else
        {
            parent -> right = x -> right ;
            x -> right -> left = parent ;
        }

        free ( x ) ;
        return ;
    }

    /* if the node to be deleted has only left child */
if ( x -> isleft == false && x -> isright == true )
    {
        /* the node to be deleted is a root node */
if ( parent == NULL )
        {
            parent = x ;
            xsucc = x -> left ;

            while ( xsucc -> right == false )
            xsucc = xsucc -> right ;

            xsucc -> right = *root ;

            ( *root ) -> left = x -> left ;

            free ( x ) ;
            return ;
        }

        if ( parent -> left == x )
        {
            parent -> left = x -> left ;
            x -> left -> right = parent ;
        }
        else
        {
            parent -> right = x -> left ;
            x -> left -> right = x -> right ;
        }

        free ( x ) ;
        return ;
    }
}

/* returns the address of the node to be deleted, address of its parent and
    whether the node is found or not */
void search ( struct thtree **root, int num, struct thtree **par,
                struct thtree **x, int *found )
{
    struct thtree *q ;

    q = ( *root ) -> left ;
    *found = false ;
    *par = NULL ;

    while ( q != *root )
    {
        /* if the node to be deleted is found */
if ( q -> data == num )
        {
            *found = true ;
            *x = q ;
            return ;
        }

        *par = q ;

        if ( q -> data > num )
        {
            if ( q -> isleft == true )
            {
                *found = false ;
                x = NULL ;
                return ;
            }
            q = q -> left ;
        }
        else
        {
            if ( q -> isright == true )
            {
                *found = false ;
                *x = NULL ;
                return ;
            }
            q = q -> right ;
        }
    }
}

/* traverses the threaded binary tree in inorder */
void inorder ( struct thtree *root )
{
    struct thtree *p ;

    p = root -> left ;

    while ( p != root )
    {
        while ( p -> isleft == false )
            p = p -> left ;

        printf ( "%d\t", p -> data ) ;

        while ( p -> isright == true )
        {
            p = p -> right ;

            if ( p == root )
                break ;

            printf ( "%d\t", p -> data ) ;

        }
        p = p -> right ;
    }
}



/* heap sort */

#include <stdio.h>

typedef struct node_tag node;
struct node_tag
{
node *pA, *pB;
int data;
};

node Q[16] =
{
{ NULL, &Q[ 1], 37 },
{ &Q[ 0], &Q[ 2], 42 },
{ &Q[ 1], &Q[ 3], 55 },
{ &Q[ 2], &Q[ 4], 11 },
{ &Q[ 3], &Q[ 5], 12 },
{ &Q[ 4], &Q[ 6], 71 },
{ &Q[ 5], &Q[ 7], 34 },
{ &Q[ 6], &Q[ 8], 35 },
{ &Q[ 7], &Q[ 9], 16 },
{ &Q[ 8], &Q[10], 61 },
{ &Q[ 9], &Q[11], 36 },
{ &Q[10], &Q[12], 49 },
{ &Q[11], &Q[13], 48 },
{ &Q[12], &Q[14], 10 },
{ &Q[13], &Q[15], 32 },
{ &Q[14], NULL, 80 },
};
node *pHead = &Q[0];

void PrintNodes(void)
{
node *p;

p = pHead;
do
{
if (p->pA == NULL)
printf(" ");
else
printf(" [%2d] -> ", p->pA->data);
printf("%2d", p->data);
if (p->pB == NULL)
printf("\n");
else
printf(" -> [%2d]\n", p->pB->data);
p = p->pB;
} while (p);
}

node *HeapSort(node *pList);
int main(void)
{
printf("Before:\n");
PrintNodes();

pHead = HeapSort(pHead);

printf("After:\n");
PrintNodes();

return 0;
}

node *HeapInsert(node *pHead, node *pNew)
{
if (pHead == NULL)
{
pNew->pA = pNew->pB = NULL;
return pNew;
}

if (pNew->data > pHead->data)
{
/* switch A/B to try to maintain balance */
pNew->pB = pHead->pA;
pNew->pA = HeapInsert(pHead->pB, pHead);
return pNew;
}
else
{
pHead->pA = HeapInsert(pHead->pA, pNew);
return pHead;
}
}

node *HeapRemove(node *pHead)
{
if (pHead == NULL)
return NULL;

if (pHead->pA == NULL)
return pHead->pB;
if (pHead->pB == NULL)
return pHead->pA;

if (pHead->pA->data > pHead->pB->data)
{
pHead->pA->pA = HeapRemove(pHead->pA);
pHead->pA->pB = pHead->pB;
return pHead->pA;
}
else
{
pHead->pB->pB = HeapRemove(pHead->pB);
pHead->pB->pA = pHead->pA;
return pHead->pB;
}
}

node *HeapSort(node *pList)
{
node *pIter = pList, *pNext, *pPrev;
node *pHead = NULL;
/* build heap */
while (pIter)
{
/* take one out of the list */
pNext = pIter->pB;
/* put it into the heap */
pHead = HeapInsert(pHead, pIter);
pIter = pNext;
}

/* tear down heap */
pPrev = NULL;
while (pHead)
{
/* take one out of the heap */
pIter = pHead;
pHead = HeapRemove(pHead);
/* put it into the list */
pIter->pA = pPrev;
if (pPrev == NULL)
pList = pIter;
else
pPrev->pB = pIter;
pPrev = pIter;
}
if (pIter)
pIter->pB = NULL;
return pList;
}

Tuesday 11 February 2014


#include"std.h"

void enqueue(int item, int *front, int *rear, int *queue, int SIZE)
{
    if(((*front == 0) && (*rear == SIZE-1)) || ((*rear) + 1 == *front))
        printf("\nElement not inserted. Queue is Full\n");
    else {
        if(*rear == SIZE-1)
            *rear = 0;
        else
            (*rear)++;
        queue[*rear] = item;
        printf("\nPush Success\n");
    }
    if(*front == -1)
        *front = 0;
}


void dequeue(int *front, int *rear, int *queue, int SIZE)
{
    if(*front == -1)
        printf("\nQueue is empty\n");
    else {
        printf("\nDeleted element is %d\n", queue[*front]);
        if(*front == *rear)
            *front = *rear = -1;
        else {
            if(*front == SIZE-1)
                *front = 0;
            else
                (*front)++;
        }
    }
}


void display(int front, int rear, int *queue, int SIZE)
{
    int i;
    if(front == -1)
        printf("\nQueue is empty\n");
    else {
        printf("\nQueue elements are\n");
        if(rear < front) {
            for(i = front; i <= SIZE-1; i++)
                printf("%d\t", queue[i]);
            for(i = 0; i <= rear; i++)
                printf("%d\t", queue[i]);
        } else {
            for(i = front; i <= rear; i++)
                printf("%d\t", queue[i]);
                printf("\n");
        }
    }
}



Monday 10 February 2014

1


#include <stdio.h>
#include <string.h>
#include <conio.h>
void main(){
    char init[27][12] = {" one "," two "," three ",
                " four "," five "," six ",
                " seven "," eight "," nine ",
                " ten "," eleven "," twelve ",
                " thirteen "," fourteen "," fifteen ",
                " sixteen "," seventeen "," eighteen ",
                " nineteen "," twenty "," thirty ",
                " fourty "," fifty "," sixty ",
                " seventy "," eight "," ninty "};
    char sthou[20]="",shund[20]="",sval1[20]="",sval2[20]="",result[100]="";
    int thou=0,hund=0,ten=0,temp=0,val1,val2,num,rem,c=0;

clrscr();
//USING COBOL LOGIC
     printf("*****AMOUNT IN WORDS*****\n\n");
     printf("Enter any value (upto 4 digits) : ");
     scanf("%d",&num);
     while(num>0){
         rem = num%10;
         c++;
         if(c<=2)
        temp = temp * 10  +rem;
         elseif(c==3)
        hund = rem;
         elseif(c==4)
        thou = rem;
         num = num/10;
     }
     while(temp>0){  //as ten contains two digit so reverse it
        rem = temp%10;
        ten = ten * 10 + rem;
        temp= temp/10;
     }

     if(thou>0){
       strcpy(sthou,init[thou-1]);
       strcat(sthou," thousand ");
       strcat(result,sthou);
     }

     if(hund>0){
       strcpy(shund,init[hund-1]);
       strcat(shund," hundred ");
       strcat(result,shund);
     }

     if(ten>0){
          if(ten>20){
          val1 = ten/10;
          val2 = ten%10;
          }
          if(val1>0){
           strcpy(sval1,init[val1+(18-1)]);
           strcat(result,sval1);
          }
          if(val2>0){
           strcpy(sval2,init[val2-1]);
           strcat(result,sval2);
          }
     }
     printf("\n\nAmount in word is as under \n");
     printf("%s",result);

getch();
}

2

int main()
02{
03int num;
04cout << "Please enter an integer between 1,000 and 1,000,000 without commas: ";
05cin >> num;
06 
07int modulus = num%1000;
08if (num >= 1000 && num <1000000) {
09cout << (num-modulus)/1000 << ',';
10if (modulus < 100) cout << '0';
11if (modulus < 10) cout << '0';
12cout << modulus << endl;
13}
14else cout << "your number is not valid" << endl;
15 
16return 0;
17}

Thursday 6 February 2014

University of Wales Swansea
Department of Computer Science
Compilers
Course notes for module CS 218
Dr. Matt Poole 2002, edited by Mr. Christopher Whyley, 2nd Semester
2006/2007
www-compsci.swan.ac.uk/~cschris/compilers


COP4020
Programming Languages



Compiler phases
Prof. Xin Yuan