Thursday, May 28, 2015

Typedef in C++

The typedef-names are aliases for existing types, and are not declarations of new types. Typedef cannot be used to change the meaning of an existing type name (including a typedef-name). Once declared, a typedef-name may only be redeclared to refer to the same type again. Typedef names are only in effect in the scope where they are visible: different functions or class declarations may define identically-named types with different meaning..



#include<iostream.h>
#include<conio.h>

typedef int usman;

typedef char name[10];

typedef struct fatima{
usman ID;
name nam;
}obj;

obj fatima1;
obj fatima2;
usman func1(usman b,usman b1)
{
name result="\nSum is= ";
usman sum;
sum=b+b1;
cout<<result<<sum;
return 0;
}

usman main(){
clrscr();
cout<<"\n Enter Two No: ";
cin>>fatima1.ID;
cin>>fatima2.ID;
cout<<"\n Enter Two Name: ";
cin>>fatima1.nam;
cin>>fatima2.nam;
cout<<"\n"<<fatima1.nam<<" "<<fatima2.nam<<"\n";
func1(fatima1.ID,fatima2.ID);
getch();
return 0;
}


Saturday, May 23, 2015

C++ Program to Find a latter from string

#include<conio.h>
#include<iostream.h>
#include<stdlib.h>

int function(char*s,char ch)
{ while(*s!='\0')
{
if(*s==ch)
return 1;
s++;
}
return 0;
}
void main(){
char s[]={"My name is usman"};
char ch='w';
if(function(s,ch)==0){
cout<<" not fount ";
}
else
cout<<"Found";

}


Friday, May 22, 2015

Shift And Rotate Instructions in Assembly Language

Shift And Rotate Instructions in Assembly Language ...

Code by Programming SeekerzZZZ...
Using Commands SHL ,SHR ,SAL ,SAR ,ROR ,ROL ,RCR ,RCL




include irvine32.inc
.data
msg byte  "  Actual No is:                             ",0
msg1 byte " No After 2 Arthmatic Right Shift (SAR):    ",0,13h,10h
msg2 byte " No After 2 Arthmatic Left Shift  (SAL):    ",0

msg3 byte " No After 2 Logical Left Shift:  (SHL)      ",0
msg4 byte " No After 2 Logical Right Shift: (SHR)      ",0

msg5 byte " No After 2 Left Rotations:  (ROL)          ",0
msg6 byte " No After 2 Right Rotations: (ROR)          ",0

msg7 byte " No After 2 Left RCL  (Rotate Carry Left):  ",0
msg8 byte " No After 2 Right RCR (Rotate Carry Right): ",0


num byte 11110001b

.code
main proc
call clrscr
call crlf

;------------------SAR---------------
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SAR al,2
call crlf

mov edx,offset msg1
call writestring
call crlf
call writebin
call crlf
;------------------SAL----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SAL al,2
call crlf

mov edx,offset msg2
call writestring
call crlf
call writebin
call crlf
;---------------ROL-----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
ROL al,2
call crlf

mov edx,offset msg5
call writestring
call crlf
call writebin
call crlf
;-----------------ROR---------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
ROR al,2
call crlf

mov edx,offset msg6
call writestring
call crlf
call writebin
call crlf
;-----------SHR------------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SHR al,2
call crlf

mov edx,offset msg4
call writestring
call crlf
call writebin
call crlf
;------------SHL------------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
SHL al,2
call crlf

mov edx,offset msg3
call writestring
call crlf
call writebin
call crlf
;----------------RCR----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
RCR al,2
call crlf

mov edx,offset msg8
call writestring
call crlf
call writebin
call crlf
;-----------------RCL----------------
call crlf
mov edx,offset msg
call writestring
call crlf
mov al,num
call writebin
RCL al,2
call crlf

mov edx,offset msg7
call writestring
call crlf
call writebin
call crlf


exit
main endp
end main


Wednesday, May 20, 2015

Red and Black Tree in C++

RED AND BLACK TREE:

All the case's of Insertion Deletion , Searching and Display " 
Using typedef and Structure user define data types.
Code in C++

↓↓↓↓↓↓↓
Code is Bellow ☺ ☻ ↓↓↓↓↓↓
↓↓↓↓↓↓


Source code:
Programming Seekerz :  ☺


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

enum rbtree_node_color { RED, BLACK };

typedef struct rbtree_node_t {
    void* key;
    void* value;
    struct rbtree_node_t* left;
    struct rbtree_node_t* right;
    struct rbtree_node_t* parent;
    enum rbtree_node_color color;
} *rbtree_node;

typedef struct rbtree_t {
    rbtree_node root;
} *rbtree;

typedef int (*compare_func)(void* left, void* right);

rbtree rbtree_create();

void* rbtree_lookup(rbtree t, void* key, compare_func compare);
void rbtree_insert(rbtree t, void* key, void* value, compare_func compare);
void rbtree_delete(rbtree t, void* key, compare_func compare);

typedef rbtree_node node;
typedef enum rbtree_node_color color;

static node grandparent(node n);
static node sibling(node n);
static node uncle(node n);
static void verify_properties(rbtree t);
static void verify_property_1(node root);
static void verify_property_2(node root);
static color node_color(node n);
static void verify_property_4(node root);
static void verify_property_5(node root);
static void verify_property_5_helper(node n, int black_count, int* black_count_path);

static node new_node(void* key, void* value, color node_color, node left, node right);
static node lookup_node(rbtree t, void* key, compare_func compare);
static void rotate_left(rbtree t, node n);
static void rotate_right(rbtree t, node n);

static void replace_node(rbtree t, node oldn, node newn);
static void insert_case1(rbtree t, node n);
static void insert_case2(rbtree t, node n);
static void insert_case3(rbtree t, node n);
static void insert_case4(rbtree t, node n);
static void insert_case5(rbtree t, node n);
static node maximum_node(node root);
static void delete_case1(rbtree t, node n);
static void delete_case2(rbtree t, node n);
static void delete_case3(rbtree t, node n);
static void delete_case4(rbtree t, node n);
static void delete_case5(rbtree t, node n);
static void delete_case6(rbtree t, node n);

node grandparent(node n) {
    //assert (n != NULL);
    //assert (n->parent != NULL); /* Not the root node */
    //assert (n->parent->parent != NULL); /* Not child of root */
    return n->parent->parent;
}
node sibling(node n) {
    //assert (n != NULL);
    //assert (n->parent != NULL); /* Root node has no sibling */
    if (n == n->parent->left)
        return n->parent->right;
    else
        return n->parent->left;
}
node uncle(node n) {
    //assert (n != NULL);
    //assert (n->parent != NULL); /* Root node has no uncle */
    //assert (n->parent->parent != NULL); /* Children of root have no uncle */
    return sibling(n->parent);
}
void verify_properties(rbtree t) {

    verify_property_1(t->root);
    verify_property_2(t->root);
    /* Property 3 is implicit */
    verify_property_4(t->root);
    verify_property_5(t->root);
t;
}
void verify_property_1(node n) {
    //assert(node_color(n) == RED || node_color(n) == BLACK);
    if (n == NULL) return;
    verify_property_1(n->left);
    verify_property_1(n->right);
}
void verify_property_2(node root) {
root;    //assert(node_color(root) == BLACK);
}
color node_color(node n) {
    return n == NULL ? BLACK : n->color;
}
void verify_property_4(node n) {
    if (node_color(n) == RED) {
//assert (node_color(n->left)   == BLACK);
//assert (node_color(n->right)  == BLACK);
//assert (node_color(n->parent) == BLACK);
    }
    if (n == NULL) return;
    verify_property_4(n->left);
    verify_property_4(n->right);
}
void verify_property_5(node root) {
    int black_count_path = -1;
    verify_property_5_helper(root, 0, &black_count_path);
}

void verify_property_5_helper(node n, int black_count, int* path_black_count) {
    if (node_color(n) == BLACK) {
        black_count++;
    }
    if (n == NULL) {
        if (*path_black_count == -1) {
            *path_black_count = black_count;
        } else {
   //assert (black_count == *path_black_count);
        }
        return;
    }
    verify_property_5_helper(n->left,  black_count, path_black_count);
    verify_property_5_helper(n->right, black_count, path_black_count);
}
rbtree rbtree_create() {
    rbtree t= new rbtree_t();
    t->root = NULL;
    verify_properties(t);
    return t;
}
node new_node(void* key, void* value, color node_color, node left, node right) {
    node newnode=new rbtree_node_t();
    newnode->key = key;
    newnode->value = value;
    newnode->color = node_color;
    newnode->left = left;
    newnode->right = right;
    if (left  != NULL)  left->parent = newnode;
    if (right != NULL) right->parent = newnode;
    newnode->parent = NULL;
    return newnode;
}
node lookup_node(rbtree t, void* key, compare_func compare) {
    node n = t->root;
    while (n != NULL) {
int comp_newnode = compare(key, n->key);
if (comp_newnode == 0) {
            return n;
} else if (comp_newnode < 0) {
            n = n->left;
        } else {
   //assert(comp_newnode > 0);
            n = n->right;
        }
    }
    return n;
}
void* rbtree_lookup(rbtree t, void* key, compare_func compare) {
    node n = lookup_node(t, key, compare);
    return n == NULL ? NULL : n->value;
}
void rotate_left(rbtree t, node n) {
    node r = n->right;
    replace_node(t, n, r);
    n->right = r->left;
    if (r->left != NULL) {
        r->left->parent = n;
    }
    r->left = n;
    n->parent = r;
}

void rotate_right(rbtree t, node n) {
    node L = n->left;
    replace_node(t, n, L);
    n->left = L->right;
    if (L->right != NULL) {
        L->right->parent = n;
    }
    L->right = n;
    n->parent = L;
}
void replace_node(rbtree t, node oldn, node newn) {
    if (oldn->parent == NULL) {
        t->root = newn;
    } else {
        if (oldn == oldn->parent->left)
            oldn->parent->left = newn;
        else
            oldn->parent->right = newn;
    }
    if (newn != NULL) {
        newn->parent = oldn->parent;
    }
}
void rbtree_insert(rbtree t, void* key, void* value, compare_func compare) {
    node inserted_node = new_node(key, value, RED, NULL, NULL);
    if (t->root == NULL) {
        t->root = inserted_node;
    } else {
        node n = t->root;
        while (1) {
   int comp_newnode = compare(key, n->key);
   if (comp_newnode == 0) {
                n->value = value;
                return;
   } else if (comp_newnode < 0) {
                if (n->left == NULL) {
                    n->left = inserted_node;
                    break;
                } else {
                    n = n->left;
}
            } else {
//assert (comp_newnode > 0);
                if (n->right == NULL) {
                    n->right = inserted_node;
                    break;
                } else {
                    n = n->right;
                }
            }
        }
        inserted_node->parent = n;
    }
    insert_case1(t, inserted_node);
    verify_properties(t);
}
void insert_case1(rbtree t, node n) {
    if (n->parent == NULL)
        n->color = BLACK;
    else
        insert_case2(t, n);
}
void insert_case2(rbtree t, node n) {
    if (node_color(n->parent) == BLACK)
        return; /* Tree is still valid */
    else
        insert_case3(t, n);
}
void insert_case3(rbtree t, node n) {
    if (node_color(uncle(n)) == RED) {
        n->parent->color = BLACK;
        uncle(n)->color = BLACK;
        grandparent(n)->color = RED;
        insert_case1(t, grandparent(n));
    } else {
        insert_case4(t, n);
    }
}
void insert_case4(rbtree t, node n) {
    if (n == n->parent->right && n->parent == grandparent(n)->left) {
        rotate_left(t, n->parent);
        n = n->left;
    } else if (n == n->parent->left && n->parent == grandparent(n)->right)
{
        rotate_right(t, n->parent);
        n = n->right;
    }
    insert_case5(t, n);
}
void insert_case5(rbtree t, node n) {
    n->parent->color = BLACK;
    grandparent(n)->color = RED;
    if (n == n->parent->left && n->parent == grandparent(n)->left)
 {
        rotate_right(t, grandparent(n));
    } else {
//assert (n == n->parent->right && n->parent == grandparent(n)->right);
        rotate_left(t, grandparent(n));
    }
}
void rbtree_delete(rbtree t, void* key, compare_func compare) {
    node child;
    node n = lookup_node(t, key, compare);
    if (n == NULL) return;  /* Key not found, do nothing */
    if (n->left != NULL && n->right != NULL) {
        /* Copy key/value from predecessor and then delete it instead */
        node pred = maximum_node(n->left);
        n->key   = pred->key;
        n->value = pred->value;
        n = pred;
    }

    //assert(n->left == NULL || n->right == NULL);
    child = n->right == NULL ? n->left  : n->right;
    if (node_color(n) == BLACK) {
        n->color = node_color(child);
        delete_case1(t, n);
    }
    replace_node(t, n, child);
    if (n->parent == NULL && child != NULL) // root should be black
        child->color = BLACK;
//    free(n);

    verify_properties(t);
}
static node maximum_node(node n) {
    //assert (n != NULL);
    while (n->right != NULL) {
        n = n->right;
    }
    return n;
}
void delete_case1(rbtree t, node n) {
    if (n->parent == NULL)
        return;
    else
        delete_case2(t, n);
}
void delete_case2(rbtree t, node n) {
    if (node_color(sibling(n)) == RED) {
        n->parent->color = RED;
        sibling(n)->color = BLACK;
        if (n == n->parent->left)
            rotate_left(t, n->parent);
        else
            rotate_right(t, n->parent);
    }
    delete_case3(t, n);
}
void delete_case3(rbtree t, node n) {
    if (node_color(n->parent) == BLACK &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        delete_case1(t, n->parent);
    }
    else
        delete_case4(t, n);
}
void delete_case4(rbtree t, node n) {
    if (node_color(n->parent) == RED &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == BLACK &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        n->parent->color = BLACK;
    }
    else
        delete_case5(t, n);
}
void delete_case5(rbtree t, node n) {
    if (n == n->parent->left &&
        node_color(sibling(n)) == BLACK &&
        node_color(sibling(n)->left) == RED &&
        node_color(sibling(n)->right) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->left->color = BLACK;
        rotate_right(t, sibling(n));
    }
    else if (n == n->parent->right &&
             node_color(sibling(n)) == BLACK &&
             node_color(sibling(n)->right) == RED &&
             node_color(sibling(n)->left) == BLACK)
    {
        sibling(n)->color = RED;
        sibling(n)->right->color = BLACK;
        rotate_left(t, sibling(n));
    }
    delete_case6(t, n);
}
void delete_case6(rbtree t, node n) {
    sibling(n)->color = node_color(n->parent);
    n->parent->color = BLACK;
    if (n == n->parent->left) {
//assert (node_color(sibling(n)->right) == RED);
        sibling(n)->right->color = BLACK;
        rotate_left(t, n->parent);
    }
    else
    {
//assert (node_color(sibling(n)->left) == RED);
        sibling(n)->left->color = BLACK;
        rotate_right(t, n->parent);
    }
}

static int compare_int(void* left, void* right);
static void print_tree(rbtree t);
static void print_tree_helper(rbtree_node n, int indent);

int compare_int(void* leftp, void* rightp) {
    int left = (int)leftp;
    int right = (int)rightp;
    if (left < right)
        return -1;
    else if (left > right)
        return 1;
    else {
//assert (left == right);
        return 0;
    }
}

#define INDENT_STEP  4

void print_tree_helper(rbtree_node n, int indent);

void print_tree(rbtree t) {
    print_tree_helper(t->root, 0);
    puts(" ");
}

void print_tree_helper(rbtree_node n, int indent) {
    int i;
    if (n == NULL) {
cout<<"\n\n \t\t --< Empty tree >--\n\n ";
return;
    }
    if (n->right != NULL) {
print_tree_helper(n->right, indent + INDENT_STEP);
    }
    for(i=0; i<indent; i++)
      cout<<" ";
    if (n->color == BLACK)
printf(" Black: %d\n", (int)n->key);
    else
printf(" Red= %d\n", (int)n->key);
    if (n->left != NULL) {
print_tree_helper(n->left, indent + INDENT_STEP);
    }
}
static int x=0;
int search1(rbtree_node n,int value) {
    int i;
    if (n == NULL) {
cout<<"\n\n \t\t --< Empty tree >--\n\n ";
return 0;
    }
    if (n->right != NULL) {
search1(n->right,value);
    }
if(value==(int)n->key){
    cout<<" \n Node is Found \n";
    if (n->color == BLACK)
printf("\nColor:: Black= %d\n", (int)n->key);
    else
printf("\nColor:: Red= %d\n", (int)n->key);
x=32;
return 0; }
    if (n->left != NULL) {
search1(n->left,value);
    }
return 0;
      }

    void search(rbtree t,int v) {
    search1(t->root, v);if( x != 32 )cout<<"\n\nNot Found...\n";
x=0;    }

void main() {

    int i,x,y,c=0;
    rbtree tree = rbtree_create();
while(!0){
    cout<<"\n============================================\n";
    cout<<"\n\nChoose Any Of Following Option:\n\n\n\t\t[ 1 for Insertion]\n\t\t";
cout<<"[ 2 for Deletion ]\n\t\t[ 3 for Display  ]\n\t\t[ 4 For Searching]\n\t\t[ 5 For Exit     ]\n\n";
    cin>>c;
    cout<<"\n============================================\n";
    switch(c){
    case 1:{
    cout<<"\n\nHow Many Values You Want To Insert: ";
    cin>>y;
    for(i=0; i<y; i++) {
    cout<<"\n Insert Value For insertion: ";
    cin>>x;
int y = rand() % 10000;
printf("\nInserting value is=  %d \n\n", x);
rbtree_insert(tree, (void*)x, (void*)y, compare_int);
}      break;    }
    case 2:{
cout<<" \n Enter Value For Deletion: ";
cin>>x;
printf("Deleting key %d\n\n", x);
rbtree_delete(tree, (void*)x, compare_int);
      break; }
    case 3:{
    print_tree(tree);
    break;
    }
    case 4:{
    cout<<"\n\nEnter A value for search: ";
    cin>>x;
    search(tree,x);
    break;}
    case 5:{
    exit(0);
    }
    default:{break;}
    }

}
}

Monday, May 18, 2015

Coping Reverse Array into Another Array

This Program Take an array and copy that array into another array after reversing it 

#include<iostream.h>
void main(){
int A[]={0,1,2,3,4,5,6,7,8,9,10};
int B[10];
cout<<"\n Array A is: ";
for(int i=0;i<=10;i++){
cout<<A[i]<<"  ";}
for(int i1=0,j=10;i1<=10;i1++,j--)
{
B[j]=A[i1];
}
cout<<"\n Array B is: ";
for(int i2=0;i2<=10;i2++){
cout<<B[i2]<<"  ";}
}



Sunday, May 17, 2015

Merge Sorting in Assembly Language

This Program Take 2 Sorted Array merge them so that the final array will also be sorted ..Assembly Program by Programming Seekerz

include irvine32.inc

.data
arr1 byte 10 DUP(?)
arr2 byte 10 DUP(?)
arr3 byte 20 DUP(?)
len1 dword ?
len2 dword ?
len3 dword ?
msg1 byte " Enter 10 Numbers in Array 1: ",0
msg2 byte " Enter 10 numbers in Array 2: ",0
msg3 byte " After Soritng:  ",0
msg4 byte "     ",0

.code
Main Proc
call clrscr
call crlf
mov edx,offset msg1
call writestring
call crlf
mov edx,offset arr1
mov ecx,lengthof arr1
mov esi,0
L1:
call readint
mov arr1[esi],al
inc esi
loop L1

call crlf
mov edx,offset msg2
call writestring
call crlf
mov edx,offset arr2
mov ecx,lengthof arr2
mov esi,0
L2:
call readint
mov arr2[esi],al
inc esi
loop L2

mov ebx,0
mov ecx,0
mov edi,0
mov len1,10
mov len2,10
mov len3,20
.while edi < len3

.if ebx < len1 &&  ecx < len2

mov al,arr2[ecx]

.if arr1[ebx] < al
mov al,arr1[ebx]
mov arr3[edi],al
inc ebx

.else
mov al,arr2[ecx]
mov arr3[edi],al
inc ecx

.endif
inc edi

.elseif ebx == len1

.while edi < len3
mov al,arr2[ecx]
mov arr3[edi],al
inc edi
inc ecx
.endw

.else


.while edi< len3
mov al,arr1[ebx]
mov arr3[edi],al
inc edi
inc ebx
.endw
.endif

.endw

mov edx,offset msg3
call writestring
call crlf
mov edx,offset arr3
mov ecx,lengthof arr3
mov esi,0

L3:
mov edx,offset msg4
call writestring

mov al,arr3[esi]
call writedec
inc esi
loop L3

exit
main endp
end main


Bubble Sort in Assembly Language

include irvine32.inc

.data
array byte 10 DUP(?)
swap byte 0
msg byte " Enter 10 NUmber: ",0
msg1 byte " After Sorting : ",0
msg2 byte "   ",0

.code
main proc
call clrscr
call crlf
mov edx,offset msg
call writestring
call crlf
mov edx,offset array
mov ecx,lengthof array
mov esi,0

L1:
call readint
mov array[esi],al
inc esi
loop L1

mov bx,1
mov ax,8

mov edx,offset array

.while bx > 0
mov bx,0
mov si,0



.while si <= ax

mov al,array[si+1]
.if array[si] > al




mov al,array[si]
xchg al,array[si+1]
mov array[si],al

mov bx,si

.endif
inc si

.endw
mov ax,bx


.endw

mov edx,offset array
mov ecx,lengthof array
mov esi,0
mov edx,offset msg1
call writestring
L2:
mov al,array[esi]
call writedec
mov edx,offset msg2
call writestring
inc esi
loop L2

exit
main endp
end main


Program to check No is Palindrome in Assembly

This Program Take a No from User Reverse it to check that it is Palindrome or Not Assembly Language Code From Programming SeekerzzZZ


include irvine32.inc

.data
num word 0
key word 0
temp word 0
i word 0
reverse word 0
msg byte "Enter the number: ",0
msg1 byte " No is Palindrome ",0
msg2 byte " Not  a Palindrome ",0

.code
Main proc
call crlf
call clrscr
mov edx,offset msg
call writestring
call readint
mov temp,ax
mov key,ax

.while temp > 0

mov dx,0
mov ax,temp
mov bx,10

div bx
mov temp,ax

mov num,dx
mov ax,num

mov ax,10
mov bx,reverse
mul bx

add ax,num
mov reverse,ax

call crlf
.endw

mov ax,key
.if reverse != ax
call crlf
mov edx,offset msg2
call writestring
.else
call crlf
mov edx,offset msg1
call writestring
.endif

exit
main endp
end main




Saturday, May 16, 2015

Binary Search Code in Assembly Language

Binary Search Code in Assembly Language ... Compiler Masm615 

include irvine32.inc

.data
array byte 10 DUP(?)
num byte ?
first byte 0
middle byte 0
last byte 0
msg1 byte " Enter 10 Number in Array : ",0
msg2 byte " Enter Number to Find: ",0
msg3 byte " Found ",0
msg4 byte " Not Found ",0

.code
main proc
call clrscr

call crlf
mov edx,offset msg1
call writestring
call crlf
mov edx,offset array
mov ecx,lengthof array
mov esi,0
L1:
call readint
mov array[esi],al
inc esi
loop L1

call crlf
mov edx,offset msg2
call writestring
call readint
mov num,al

mov al,lengthof array
add al,first
mov bl,2
div bl
mov middle,al
mov bl,first
.while bl <= last
movzx si,middle
mov al,num
.if array[si] < al
mov al,middle
add al,1
mov first,al
mov al,num

.elseif array[si] == al
mov edx,offset msg3
call writestring
call crlf
jmp e

.else

mov al,middle
sub al,1
mov last,al
add al,first
mov bl,2
div bl
mov middle,al
.endif
.endw


mov edx,offset msg4
call writestring
call crlf


e:
exit
main endp

end main


Heart ♥ in C++ .. ☻

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

void main()
{
clrscr();
int num;
cout<<"Please Enter Number : ";
cin>>num;
cout<<"\n\n";
int g=num*2, x=num/2, v=0, m=num,n=0;

for(int q=0;q<(num/2);q++)
{
for(int u=0;u<x;u++)
printf(" ");
x--;
cout<<char(3);
for(int o=0;o<v;o++)
printf(" ");
v+=2;
cout<<char(3);
for(int l=0;l<m-1;l++)
printf(" ");
m-=2;
cout<<char(3);
for(int a=0;a<n;a++)
printf(" ");
n+=2;
cout<<char(3);
printf("\n");

}

for(int i=0;i<num;i++)
{
int s,j;
for(s=0;s<=i;s++)
{
printf(" ");
}
cout<<char(3);
for(j=0;j<g-1;j++)
{
printf(" ");
}
g-=2;
cout<<char(3);
printf("\n");
if(i==(num-1))
{
for(int f=0;f<(num+1);f++)
printf(" ");
cout<<char(3);
}
}
getch();
}


Thursday, May 14, 2015

.IF statement in Assembly Language

Write an assembly program that take age of 50 people and count the number of people lives in the age group given below ? Also print the age
 20 - 30 years
 40 - 50 years
 35 - 45 years
 25 - 45 years

include irvine32.inc

.data
msg byte ":  Enter a No: ",0
msg2 byte " Sory Range Not Found ",0
r1 byte "  --Range 20 - 30 years--  ",0
r2 byte "  --Range 40 - 50 years--  ",0
r3 byte "  --Range 35 - 45 years--  ",0
r4 byte "  --Range 25 - 45 years--  ",0

rr1 dword 0
rr2 dword 0
rr3 dword 0
rr4 dword 0

num dword 0
i dword 0

.code
Main proc
call clrscr
call crlf

.while i != 50
call crlf
call crlf

mov eax,i
call writedec
mov edx,offset msg
call writestring
call readint
mov num,eax

.if eax < 20 || eax > 50
call crlf
mov edx,offset msg2
call writestring
.endif

.if eax >= 20 && eax <=30
inc rr1
call crlf
mov edx,offset r1
call writestring

.endif

.if eax >= 40 && eax <= 50
inc rr2
call crlf
mov edx,offset r2
call writestring

.endif

.if eax >= 35 && eax <= 45
inc rr3
call crlf
mov edx,offset r3
call writestring

.endif

.if eax >= 25 && eax <= 45
inc rr4
call crlf
mov edx,offset r4
call writestring

.endif
inc i
.endw

call crlf
call crlf
mov edx,offset r1
call writestring
mov eax,rr1
call writedec
call crlf

mov edx,offset r2
call writestring
mov eax,rr2
call writedec
call crlf

mov edx,offset r3
call writestring
mov eax,rr3
call writedec
call crlf

mov edx,offset r3
call writestring
mov eax,rr3
call writedec
call crlf
exit
main endp
end main


Saturday, May 9, 2015

Turbo c++ for android { Complete guide of installation }

Hello guys, today in this post I will explain how to download and install turbo c++ in android. I am sure you are aware about for turbo c++. Well turbo c++ is one type of compiler which is specially designed for c/c++ .One can easily perform most of the c/c++ programs with help of turbo c++! We already provided turbo c++ for windows xp/7/8/8.1! Well this post is especially for those who want to do programming in c or c++ in their android phones! So I will provide you guide How to install and use turbo c++ in your android phone! Just read full guide of turbo c++ for android!

Turbo c++ for android

Steps to install turbo c++ for android 


1.  First of all you need to download one zip in your android phone

  Click here to download the zip file for turbo c++ for android


2.  Now download one apk file Easy unrar from playstore! This apk file is needed for extracting the downloaded file of turbo c++ in your android phone! You can use other apks also for this operation

3.  Now open Easy unrar file and search the downloaded file (Given in step 1) and select it for extract it to the desired location

4. All the files will be there. You will find to files there .One is "Tc" folder and one is DOSbox apk.

5. You need to install DOSbox by clicking on it

6. After installing the DOSbox you need to move all extracted file in other location of SD card

7.  Now time to open DOSbox. Open DOSbox and click start emulator

8. You will see black screen like this.

9. Write following commands there

  cd tc
cd bin
tc

10. You will find the blue screen of turbo c++ on android

That’s it! You have successfully installed turbo c++ in your android phone!

Please note: This is tested by me and its working on any android device

So this is the complete process to install turbo c++ in android device! You can easily write the program there and run it on your android device. Enjoy programming on android device! Enjoy c/c++ programming! If you have still have any doubts or any difficulty in this post turbo c++ for  android device, Fill free to ask! I will help you!

Friday, May 8, 2015

Program to generate 20 Even no and then saved and display them by after making Odd

Program to generate 20  Even no and then saved and display them by after making Odd
Assembly Language 

include irvine32.inc

.data
arr dword 20 DUP(?)
msg byte " Even NO: ",0,13h,10h
msg1 byte " After converting it into ODD: ",0,13h,10h
count dword 0
num dword 0
divied dword 0

.code
main proc
call clrscr
call crlf

mov esi,0
.while count != 20
;call randomize
call random32

mov eax,100
call randomrange

mov num,eax
mov edx,0
mov ebx,2
div ebx

.IF edx == 0
.IF num < 42

call crlf
mov edx,offset msg
call writestring

call settextcolor
mov eax,100
call delay

mov eax,num
call writedec
mov arr[esi],eax
add esi,4
inc count

.endif
.endif
.endw

mov esi,0
mov count,0

call crlf

.repeat
call crlf
mov edx,offset msg1
call writestring

mov eax,arr[esi]
add eax,1
call writeint
add esi,4
inc count

.until count == 20

exit
main endp

end main


Tuesday, May 5, 2015

Make all values of tree negative -ive

#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){

  Node* newnode = new Node();

  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void makeneg(Node *r){
  if (r == NULL) return;
  else {
   makeneg(r->left);
   r->data=r->data*(-1);
   makeneg(r->right);
   }
 }

 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   cout << r->data <<"  ";
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={19,54,63,22,75,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\n\n";
 b.inorder(b.root);
 b.makeneg(b.root);
 cout<<"\n\nAfter Making all  values Nagitive -ive: \n\n ";
 b.inorder(b.root);
 getch();

}


Making all even values odd in a tree




#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){

  Node* newnode = new Node();

  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void makeeven(Node *r){
  if (r == NULL) return;
  else {
   makeeven(r->left);
   if(r->data % 2 == 0){
   r->data=r->data+1;              }
   makeeven(r->right);
   }
 }

 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   cout << r->data <<"  ";
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={19,54,63,22,75,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\n\n";
 b.inorder(b.root);
 b.makeeven(b.root);
 cout<<"\n\nAfter Making all even values Odd: \n\n ";
 b.inorder(b.root);
 getch();

}

Make all Odd values Even in a tree

#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){

  Node* newnode = new Node();

  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void makeeven(Node *r){
  if (r == NULL) return;
  else {
   makeeven(r->left);
   if(r->data % 2 != 0){
   r->data=r->data+1;              }
   makeeven(r->right);
   }
 }

 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   cout << r->data <<"  ";
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={19,54,63,22,75,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\n";
 b.inorder(b.root);
 b.makeeven(b.root);
 cout<<"\nAfter Making all Odd values even: \n ";
 b.inorder(b.root);
 getch();

}


Display only Odd values from tree



#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){

  Node* newnode = new Node();

  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   if(r->data % 2 != 0){
   cout << r->data <<"  ";             }
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={9,4,3,2,5,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\nDisplaing only ODD values:\n\n";
 b.inorder(b.root);
 getch();

}

Display only even Values from tree

#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){
 
  Node* newnode = new Node();
 
  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   if(r->data % 2 == 0){
   cout << r->data <<"  ";             }
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={9,4,3,2,5,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\nDisplaing only Even values:\n\n";
 b.inorder(b.root);
 getch();

}

Write a Function to display only leaf nodes

#include<iostream.h>
#include<conio.h>
class Node{
private:
 int data;
 Node* right;
 Node* left;
public:
 Node(){
  root=NULL;
  right=left=NULL;
 }Node *root;

 void insert(int data){

  Node* newnode = new Node();

  newnode->data = data;
   if (root == NULL){
   root=newnode;
   return;
  }
  Node *p,*q;
  p=q=root;
  while (q!=NULL){
   p=q;
   if (newnode->data> q->data)
    q = q->right;
   else q = q->left;
  }
  if (newnode->data> p->data)
   p->right = newnode;
  else p->left = newnode;
 }



 void inorder(Node *r){
  if (r == NULL) return;
  else {
   inorder(r->left);
   if(r->left==NULL && r->right==NULL){
   cout << r->data <<"  ";             }
   inorder(r->right);
   }
 }



};

void main()
{
int c,A[]={9,4,3,2,5,6,8,1,33,12,44};
 Node b;
 clrscr();
 for(int i=0;i<=10;i++){
 b.insert(A[i]); }
 cout<<"\nIn-Order display :\nDisplaing only leaf nodes:\n\n";
 b.inorder(b.root);
 getch();

}


Saturday, May 2, 2015

Using AND convert lower alphabets into upper ~ Assembly Programs

This Program Use AND operator to Convert lower alphabets into upper
x   y   x^y
1   0    0
0   0    0  
1   1    1
0   1    0


include irvine32.inc
.data

  alp byte ?
  msg byte "Please Enter an Alphabet to Make it in upper latter: ",0,13h,10h
  msg1 byte "In upper Latter:  ",0,13h,10h
  msg2 byte "Latter is :  ",0,13h,10h
  msg3 byte "Binary is :   ",0,13h,10h
  msg4 byte "ASCII is  : ",0,13h,10h

.code
  main proc
call clrscr
call crlf
     mov edx,offset msg
     call writestring
call crlf
call crlf
     mov edx,offset msg2
     call writestring
     mov edx,offset alp
     call readchar

     call writechar
call crlf
     mov edx,offset msg3
     call writestring
     call writebin
call crlf
     mov edx,offset msg4
     call writestring
     call writedec

call crlf
AND al,11011111b
call crlf
mov edx,offset msg1
     call writestring
call crlf
     mov edx,offset msg3
     call writestring

call writebin
call crlf
     mov edx,offset msg2
     call writestring
call writechar
call crlf
     mov edx,offset msg4
     call writestring
     call writedec

      exit
     main endp
   end main

Friday, May 1, 2015

check parity of 8-bit number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num byte 122
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov al,num
call writebin

XOR al,0
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main

Check parity of 16-bit number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num word 39263
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov ax,num
call writebin
mov ax,num
XOR al,ah
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main

Check Parity of 32-bit Number Assembly Program

See Also: Check Parity of 32-bit Number Assembly Program
                 Check Parity of 16-bit Number Assembly Program
                 Check Parity of 8  -bit Number Assembly Program


include irvine32.inc
.data
   
num dword 3043274211
msg  byte "Parity Flag is set   : PF=EVEN ",0,13h,10h
msg1 byte "Parity flag is clear : PF=ODD  ",0,13h,10h

.code
main proc
call clrscr
call crlf
mov eax,num
call writebin
mov al,byte ptr num
mov ah,byte ptr num+1
XOR al,ah
mov ah,byte ptr num+2
XOR al,ah
mov ah,byte ptr num+3
XOR al,ah
cmp al,0
JP L1
JNP L2
L2:
call crlf
mov edx,offset msg1
call writestring
jmp e

L1:
call crlf
mov edx,offset msg
call writestring
jmp e
e:
exit
main endp
end main


Insert 100 in all Leaf nodes and 10 in all non leaf nodes using BST

Insert 100 in all Leaf nodes and 10 in all non leaf nodes using BST in C++

#include<iostream.h>
#include<conio.h>
class Node{
private:
int data;
Node* right,*q,*p;
Node* left;
public:
Node(){
root=NULL;
right=left=NULL;
}Node *root;

void insert(int data){

Node* newnode = new Node();

newnode->data = data;
if (root == NULL){
root=newnode;
return;
}
Node *p,*q;
p=q=root;

while (q!=NULL){
p=q;
if (newnode->data> q->data)
q = q->right;
else q = q->left;
}
if (newnode->data> p->data)
p->right = newnode;
else p->left = newnode;
}


void inorder(Node *r){
if (r == NULL) return;
else {
inorder(r->left);
if(r->left==NULL && r->right==NULL){
r->data=100;}
else r->data=10;
cout << r->data <<"  ";
inorder(r->right);
} }

void _inorder(Node *r){
if (r == NULL) return;
else {
      _inorder(r->left);
cout << r->data <<"  ";
if(r->left==NULL && r->right==NULL){
r->data=100;}
_inorder(r->right);
} }

};

void main()
{
int c,A[]={9,4,3,2,5,6,8,1,33,12,44};
Node b;
clrscr();
for(int i=0;i<=10;i++){
b.insert(A[i]); }
cout<<"\n\n\nSimple Tree: BST inorder:\n \n";
b._inorder(b.root);
cout<<"\n\n\nAfter Puting 100 in all leaf Node:\n \n";
b._inorder(b.root);
cout<<"\n\n\nAfter Puting 10 in all Non leaf Node:\n\n ";
b.inorder(b.root);
getch();

}



Take Maximum Node Make it Root Node

Take Maximum Node Make it Root Node and attach rest of tree with it so that BST Property will not volatilized 

#include<iostream.h>
#include<conio.h>
class Node{
private:
int data,i;
Node* right,*q,*p;
Node* left;
public:
Node(){
root=NULL;
right=left=NULL;
}Node *root;


Node* remove(Node *root, int value){
Node *t;
int cmpr = value - root->data;
if (cmpr < 0){
t = remove(root->left, value);
root->left = t;
} else if (cmpr > 0){
t = remove(root->right, value);
root->right = t;
} else if (root->left != NULL && root->right != NULL){
Node* minNode;
minNode = findMin(root->right);
root->data = minNode->data;
t = remove(root->right, minNode->data);
root->right = t;
} else {
Node* nodeToDelete = root;
if (root->left == NULL)
root = root->right;
else if (root->right == NULL)
root = root->left;
else root = NULL;
delete nodeToDelete;
}       return root;
}

void insert(int data){
Node* newnode = new Node();
newnode->data = data;
if (root == NULL){
root=newnode;
return;
}       Node *p,*q;
p=q=root;
while (q!=NULL){
p=q;
if (newnode->data> q->data)
q = q->right;
else q = q->left;
}
if (newnode->data> p->data)
p->right = newnode;
else p->left = newnode;
}

Node* findMax(Node* te)
{
if (te->right == NULL){
return te;           }
return findMax(te->right);
}

Node* findMin(Node* te)
{
if (te->left == NULL){
return te;           }
return findMin(te->left);
}

 void _preorder(Node *root){
if (root == NULL) return;
else {  B[i]=root->data;
i++;
_preorder(root->left);
_preorder(root->right);
} }

void preorder(Node *root){
if (root == NULL) return;
else {  cout <<root->data <<"  ";B[i]=root->data;
i++;
preorder(root->left);
preorder(root->right);
} }

void inorder(Node *root){
if (root == NULL) return;
else {
inorder(root->left);
cout << root->data <<"  ";
inorder(root->right);
} }



 void Max_to_root(){
root->data=(findMax(root)->data);
remove(root->right,root->data);
i=0;
cout<<endl;
_preorder(root);
}
int B[];


};

void main()
{
int c,A[]={9,4,3,2,5,6,8,1,33,12,44};
Node b,obj;
clrscr();
for(int i=0;i<=10;i++){
b.insert(A[i]); }
cout<<"\n\nInorder triversal: ";
b.inorder(b.root);
cout<<"\n\nPreOrder triversal: ";
b.preorder(b.root);
b.Max_to_root();

   for(int j=0;j<=10;j++){
   obj.insert(obj.B[j]);}

  cout<<"\n\nAfter Process: \n\nInorder: ";
  obj.inorder(b.root);

  cout<<"\n\nPreorder: ";
  obj.preorder(b.root);

   getch();
}