Sunday, 25 November 2012

All HTML tags

All HTML tags

Tag Description
<!--...--> Defines a comment
<!DOCTYPE>  Defines the document type
<a> Defines a hyperlink
<abbr> Defines an abbreviation
<acronym> Not supported in HTML5. Defines an acronym
<address> Defines contact information for the author/owner of a document
<applet> Not supported in HTML5. Deprecated in HTML 4.01. Defines an embedded applet
<area> Defines an area inside an image-map
<article>New Defines an article
<aside>New Defines content aside from the page content
<audio>New Defines sound content
<b> Defines bold text
<base> Specifies the base URL/target for all relative URLs in a document
<basefont> Not supported in HTML5. Deprecated in HTML 4.01. Specifies a default color, size, and font for all text in a document
<bdi>New Isolates a part of text that might be formatted in a different direction from other text outside it
<bdo> Overrides the current text direction
<big> Not supported in HTML5. Defines big text
<blockquote> Defines a section that is quoted from another source
<body> Defines the document's body
<br> Defines a single line break
<button> Defines a clickable button
<canvas>New Used to draw graphics, on the fly, via scripting (usually JavaScript)
<caption> Defines a table caption
<center> Not supported in HTML5. Deprecated in HTML 4.01. Defines centered text
<cite> Defines the title of a work
<code> Defines a piece of computer code
<col> Specifies column properties for each column within a <colgroup> element 
<colgroup> Specifies a group of one or more columns in a table for formatting
<command>New Defines a command button that a user can invoke
<datalist>New Specifies a list of pre-defined options for input controls
<dd> Defines a description of an item in a definition list
<del> Defines text that has been deleted from a document
<details>New Defines additional details that the user can view or hide
<dfn> Defines a definition term
<dir> Not supported in HTML5. Deprecated in HTML 4.01. Defines a directory list
<div> Defines a section in a document
<dl> Defines a definition list
<dt> Defines a term (an item) in a definition list
<em> Defines emphasized text 
<embed>New Defines a container for an external (non-HTML) application
<fieldset> Groups related elements in a form
<figcaption>New Defines a caption for a <figure> element
<figure>New Specifies self-contained content
<font> Not supported in HTML5. Deprecated in HTML 4.01. Defines font, color, and size for text
<footer>New Defines a footer for a document or section
<form> Defines an HTML form for user input
<frame> Not supported in HTML5. Defines a window (a frame) in a frameset
<frameset> Not supported in HTML5. Defines a set of frames
<h1> to <h6> Defines HTML headings
<head> Defines information about the document
<header>New Defines a header for a document or section
<hgroup>New Groups heading (<h1> to <h6>) elements
<hr> Defines a thematic change in the content
<html> Defines the root of an HTML document
<i> Defines a part of text in an alternate voice or mood
<iframe> Defines an inline frame
<img> Defines an image
<input> Defines an input control
<ins> Defines a text that has been inserted into a document
<kbd> Defines keyboard input
<keygen>New Defines a key-pair generator field (for forms)
<label> Defines a label for an <input> element
<legend> Defines a caption for a <fieldset>, < figure>, or <details> element
<li> Defines a list item
<link> Defines the relationship between a document and an external resource (most used to link to style sheets)
<map> Defines a client-side image-map
<mark>New Defines marked/highlighted text
<menu> Defines a list/menu of commands
<meta> Defines metadata about an HTML document
<meter>New Defines a scalar measurement within a known range (a gauge)
<nav>New Defines navigation links
<noframes> Not supported in HTML5. Defines an alternate content for users that do not support frames
<noscript> Defines an alternate content for users that do not support client-side scripts
<object> Defines an embedded object
<ol> Defines an ordered list
<optgroup> Defines a group of related options in a drop-down list
<option> Defines an option in a drop-down list
<output>New Defines the result of a calculation
<p> Defines a paragraph
<param> Defines a parameter for an object
<pre> Defines preformatted text
<progress>New Represents the progress of a task
<q> Defines a short quotation
<rp>New Defines what to show in browsers that do not support ruby annotations
<rt>New Defines an explanation/pronunciation of characters (for East Asian typography)
<ruby>New Defines a ruby annotation (for East Asian typography)
<s> Defines text that is no longer correct
<samp> Defines sample output from a computer program
<script> Defines a client-side script
<section>New Defines a section in a document
<select> Defines a drop-down list
<small> Defines smaller text
<source>New Defines multiple media resources for media elements (<video> and <audio>)
<span> Defines a section in a document
<strike> Not supported in HTML5. Deprecated in HTML 4.01. Defines strikethrough text
<strong> Defines important text
<style> Defines style information for a document
<sub> Defines subscripted text
<summary>New Defines a visible heading for a <details> element
<sup> Defines superscripted text
<table> Defines a table
<tbody> Groups the body content in a table
<td> Defines a cell in a table
<textarea> Defines a multiline input control (text area)
<tfoot> Groups the footer content in a table
<th> Defines a header cell in a table
<thead> Groups the header content in a table
<time>New Defines a date/time
<title> Defines a title for the document
<tr> Defines a row in a table
<track>New Defines text tracks for media elements (<video> and <audio>)
<tt> Not supported in HTML5. Defines teletype text
<u> Defines text that should be stylistically different from normal text
<ul> Defines an unordered list
<var> Defines a variable
<video>New Defines a video or movie
<wbr>New Defines a possible line-break

Tuesday, 6 November 2012

executing all file and directory handling commands


executing all file and directory handling commands

[root@domain30 984D-171A]# cal
    October 2012  
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

[root@domain30 984D-171A]# date
Fri Oct 19 19:20:27 IST 2012

[root@domain30 984D-171A]# echo "welcome to MIT"
welcome to MIT

[root@domain30 984D-171A]# printf "this is IT department"
this is IT department

[root@domain30 984D-171A]# who
MAHESH   tty1         2012-10-19 19:18 (:0)
MAHESH   pts/0        2012-10-19 19:19 (:0.0)


[root@domain30 984D-171A]# who am i
MAHESH   pts/0        2012-10-19 19:19 (:0.0)

[root@domain30 984D-171A]# uname
Linux

[root@domain30 984D-171A]# tty
/dev/pts/0

[root@domain30 mahesh]# pwd
/mahesh

[root@domain30 mahesh]# ls
2.txt  7  fifth.sh  op2.txt  op.txt  secound.sh  sixth.sh  third.sh

[root@domain30 mahesh]# ls -l
total 28
-rw-r--r--. 1 root   root    19 Oct 18 14:07 2.txt
-rw-r--r--. 1 root   root     0 Oct 18 14:30 7
-rw-r--r--. 1 root   root   170 Oct 12 21:44 fifth.sh
-rw-r--r--. 1 root   root   148 Oct 18 21:05 op2.txt
-rw-r--r--. 1 root   root   148 Oct 18 14:09 op.txt
-rw-r--r--. 1 root   root   667 Oct 18 21:03 secound.sh
-rwxr-xr-x. 1 MAHESH MAHESH 558 Oct 13 16:46 sixth.sh
-rwxr-xr-x. 1 MAHESH MAHESH 500 Oct 12 23:43 third.sh

[root@domain30 mahesh]# mkdir MIT
[root@domain30 mahesh]# ls
2.txt  7  fifth.sh  MIT  op2.txt  op.txt  secound.sh  sixth.sh  third.sh

[root@domain30 mahesh]# rmdir MIT
[root@domain30 mahesh]# ls
2.txt  7  fifth.sh  op2.txt  op.txt  secound.sh  sixth.sh  third.sh



[root@domain30 mahesh]# mkdir ITSE

[root@domain30 mahesh]# mv  ITSE MIT1

[root@domain30 mahesh]# cd ITSE
bash: cd: ITSE: No such file or directory

[root@domain30 mahesh]# rmdir MIT1/

[root@domain30 mahesh]# mkdir ITSE
[root@domain30 mahesh]# vim ITSE/MIT1
[root@domain30 mahesh]# ls ITSE/
MIT1


[root@domain30 mahesh]# more sixth.sh
echo "1.Display the pid of login shell "
echo "2.Display process status "
echo "3.Display detailed listing of processes "
echo "4.Display process of user "
echo "5.Display all users processes "
printf "Enter choice : "
read choice
if [ $choice == 1 ]
then
echo "PID of current shell is : $$"
fi
if [ $choice == 2 ]
then
ps
fi
if [ $choice == 3 ]
then
ps -f
fi
if [ $choice == 4 ]
then
printf "Enter user name : "
read user
ps -u $usr
fi
if [ $choice == 5 ]
then
ps -a
fi
if [ $choice == 6 ]
then
ps -e
else [ $choice > 7 ]
echo "Incorrect choice !"
fi

[root@domain30 mahesh]# file sixth.sh
sixth.sh: ASCII English text

[root@domain30 mahesh]# wc sixth.sh
 41 123 558 sixth.sh

[root@domain30 mahesh]# wc -l sixth.sh
41 sixth.sh


[root@domain30 mahesh]# vim mahi.txt
[root@domain30 mahesh]# od mahi.txt
0000000 064164 071551 064440 020163 064563 070155 062554 063040
0000020 066151 005145
0000024

[root@domain30 mahesh]# cat mahi.txt
this is simple file

[root@domain30 mahesh]# cat mahi.txt
this is simple file
[root@domain30 mahesh]# cat mahi1.txt
it secound simple file
[root@domain30 mahesh]# cmp mahi.txt mahi1.txt
mahi.txt mahi1.txt differ: byte 1, line 1

[root@domain30 mahesh]# comm mahi.txt mahi1.txt
it secound simple file
this is simple file

[root@domain30 mahesh]# diff mahi.txt mahi1.txt
1c1
< this is simple file
---
> it secound simple file


[root@domain30 mahesh]# chmod 421 mahi.txt

[root@domain30 mahesh]# ls -l
total 40
-rw-r--r--. 1 root   root     19 Oct 18 14:07 2.txt
-rw-r--r--. 1 root   root      0 Oct 18 14:30 7
-rw-r--r--. 1 root   root    170 Oct 12 21:44 fifth.sh
drwxr-xr-x. 2 root   root   4096 Oct 19 19:26 ITSE
-rw-r--r--. 1 root   root     23 Oct 19 19:30 mahi1.txt
-r---w---x. 1 root   root     20 Oct 19 19:29 mahi.txt
-rw-r--r--. 1 root   root    148 Oct 18 21:05 op2.txt
-rw-r--r--. 1 root   root    148 Oct 18 14:09 op.txt
-rw-r--r--. 1 root   root    667 Oct 18 21:03 secound.sh
-rwxr-xr-x. 1 MAHESH MAHESH  558 Oct 13 16:46 sixth.sh
-rwxr-xr-x. 1 MAHESH MAHESH  500 Oct 12 23:43 third.sh

shell script to perform operations on string

shell script to perform operations on string

*day.sh

#!/bin/bash
day=`date "+%a"`
if [ "$day"=="mon" ]
then
echo "weekend is over"
fi
~   

OUTPUT:[root@domain30 fourth]# sh day.sh 

weekend is over


*cmp.sh

#!/bin/bash
com="wipro"
if [ "$com" \< "z" ]
then
echo "the comapny name being with the letter less than z"
fi

OUTPUT:[root@domain30 fourth]# sh cmp.sh 

the comapny name being with the letter less than z


*strmerg.sh

#!/bin/bash
echo "enter the first name-->"
read fst

echo "enter the last name-->"

read lst

echo "the complete string is--> $fst$lst"



OUTPUT:

[root@domain30 fourth]# sh strmerg.sh 
enter the first name-->
mahesh
enter the last name-->
maske
the complete string is--> maheshmaske
                                                                                                                                              
                                                                                                                                              
                                                                                                                                                                                                                                                                                           
                                                                                                                              
*strlength.sh

#!/bin/bash
str=mahesh
echo ${#str}
echo `expr length $str`
echo `expr "$str"`


OUTPUT:

[root@domain30 fourth]# sh mahesh.sh 
6
6
mahesh                                                                                                                                              
                                                                                                                                              
                                                                                                                                              
                                                                                                                                              
      


system administrative commands

system administrative commands



[MAHESH@domain30 mahesh]$ pwd
/mahesh


[MAHESH@domain30 mahesh]$ su
Password: ******
[root@domain30 mahesh]#

[root@domain30 mahesh]# date

Fri Oct 19 20:40:26 IST 2012

[root@domain30 Desktop]# passwd
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

[root@domain30 Desktop]# ulimit 20791510

[root@domain30 Desktop]# wall
i am student of SEIT

Broadcast message from root@domain30 (pts/0)(Sat Oct 13 11:03:07

i am student of SEIT

[root@domain30 mahesh]# chmod 1775 arithmetic.sh
[root@domain30 mahesh]# ls -l
total 52
-rw-r--r--. 1 root   root      0 Oct 19 19:51 25
-rw-r--r--. 1 root   root     19 Oct 18 14:07 2.txt
-rw-r--r--. 1 root   root      0 Oct 18 14:30 7
-rwxrwxr-t. 1 root   root    173 Oct 19 19:38 arithmetic.sh
-rw-r--r--. 1 root   root    170 Oct 12 21:44 fifth.sh


[root@domain30 mahesh]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_domain30-lv_root
                      43872748   2806724  38837392   7% /
tmpfs                  1935592       272   1935320   1% /dev/shm
/dev/sda5               495844     35372    434872   8% /boot
/dev/sdb1              3912656      2100   3910556   1% /media/984D-171A

[root@domain30 mahesh]# du
20 ./fourth
8 ./ITSE
76 .





shell script for total user info


shell script for total user info


#!/bin/bash
echo "my name is :"$LOGNAME
echo "my name is :"$USER
echo "my HOME DIRECTORY IS :"$HOME
echo "my WORKING SHELL IS :"$SHELL
echo "my AVALABLE PATH is :"$PATH

OUTPUT:

[MAHESH@domain30 mahesh]$ sh fifth.sh 
my name is :MAHESH
my name is :MAHESH
my HOME DIRECTORY IS :/home/MAHESH
my WORKING SHELL IS :/bin/bash
my AVALABLE PATH is :/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/MAHESH/bin:/home/MAHESH/bin


shell script for arithmatic operations


shell script for arithmatic operations

#!/bin/bash
a=10
b=5

val=`expr $a + $b`
echo "a+b=" $val


val=`expr $a - $b`
echo "a-b=" $val


val=`expr $a \* $b`
echo "a*b=" $val


val=`expr $a / $b`
echo "a/b=" $val




OUTPUT:
[root@domain30 mahesh]# vim arithmetic.sh
[root@domain30 mahesh]# sh arithmetic.sh
a+b= 15
a-b= 5
a*b= 50
a/b= 2

Tuesday, 16 October 2012

Write a Program of Binary Search Tree Operations.

Write a Program of Binary Search Tree Operations.

#include <iostream.h>
#include <process.h> //for exit(1)
#include <conio.h>

struct node{
    int data;
    struct node *left;
    struct node *right;
};

class BST{
    public:
    node *tree;
    BST(){
        tree=NULL;
    }
    void createTree(node **,int item);    //For Building Treevoid preOrder(node *);     //For Tree Traversalvoid inOrder(node *);
    void postOrder(node *);

    void determineHeight(node *,int *);
    int totalNodes(node *);
    int internalNodes(node *); //no. of non-leaf nodesint externalNodes(node *); //no. of leaf nodes.void removeTree(node **); //Remove tree from memory.

    node **searchElement(node **,int);
    void findSmallestNode(node *);
    void findLargestNode(node *);
    void deleteNode(int);
};


//it is used for inseting an single element in//a tree, but if calls more than once will create tree.void BST :: createTree(node **tree,int item){
    if(*tree == NULL){
        *tree = new node;
        (*tree)->data = item;
        (*tree)->left = NULL;
        (*tree)->right = NULL;
    }
    else{
        if( (*tree)->data > item)
            createTree( &((*tree)->left),item);
        else
            createTree( &((*tree)->right),item);
    }
}


void BST :: preOrder(node *tree){
    if( tree!=NULL){
        cout<<"   "<< tree->data;
        preOrder(tree->left);
        preOrder(tree->right);
    }
}

void BST :: inOrder(node *tree){
    if( tree!=NULL){
        inOrder( tree->left);
        cout<<"   "<< tree->data;
        inOrder(tree->right);
    }
}


void BST :: postOrder(node *tree){
    if( tree!=NULL){
        postOrder( tree->left);
        postOrder( tree->right);
        cout<<"   "<<tree->data;
    }
}


void BST :: determineHeight(node *tree, int *height){
    int left_height, right_height;
    if( tree == NULL)
        *height = 0;
    else{
        determineHeight(tree->left, &left_height);
        determineHeight(tree->right, &right_height);
        if( left_height > right_height)
            *height = left_height + 1;
        else
            *height = right_height + 1;
    }
}


int BST :: totalNodes(node *tree){
    if( tree == NULL)
        return 0;
    elsereturn( totalNodes(tree->left) + totalNodes(tree->right) + 1 );
}

int BST :: internalNodes(node *tree){
    if( (tree==NULL)  || (tree->left==NULL  && tree->right==NULL))
        return 0;
    elsereturn( internalNodes(tree->left) + internalNodes(tree->right) + 1 );
}

int BST :: externalNodes(node *tree){
    if( tree==NULL )
        return 0;
    elseif( tree->left==NULL  && tree->right==NULL)
        return 1;
    elsereturn( externalNodes(tree->left) + externalNodes(tree->right));
}

void BST :: removeTree(node **tree){
    if( (*tree) != NULL){
        removeTree( &(*tree)->left );
        removeTree( &(*tree)->right );
        delete( *tree );
    }
}

node ** BST :: searchElement(node **tree, int item){
    if( ((*tree)->data == item) || ( (*tree) == NULL) )
        return tree;
    elseif( item < (*tree)->data)
        return searchElement( &(*tree)->left, item);
    elsereturn searchElement( &(*tree)->right, item);
}

void BST :: findSmallestNode(node *tree){
    if( tree==NULL || tree->left==NULL)
        cout<< tree->data;
    else
        findSmallestNode( tree->left);
}


//Finding In_order Successor of given node..//for Delete Algo.
node * find_Insucc(node *curr)
{
    node *succ=curr->right; //Move to the right sub-tree.if(succ!=NULL){
        while(succ->left!=NULL)    //If right sub-tree is not empty.
            succ=succ->left; //move to the left-most end.
    }
    return(succ);
}


void BST :: findLargestNode(node *tree){
    if( tree==NULL || tree->right==NULL)
        cout<<tree->data;
    else
        findLargestNode(tree->right);
}


void BST :: deleteNode(int item){
    node *curr=tree,*succ,*pred;
    int flag=0,delcase;
    //step to find location of nodewhile(curr!=NULL && flag!=1)
    {
        if(item < curr->data){
            pred = curr;
            curr = curr->left;
        }
        elseif(item > curr->data){
            pred = curr;
            curr = curr->right;
        }
        else{ //curr->data = item
            flag=1;
        }
    }

    if(flag==0){
        cout<<"\nItem does not exist : No deletion\n";
        getch();
        goto end;
    }

    //Decide the  case of deletionif(curr->left==NULL && curr->right==NULL)
        delcase=1; //Node has no childelseif(curr->left!=NULL && curr->right!=NULL)
        delcase=3; //Node contains both the childelse
        delcase=2; //Node contains only one child//Deletion Case 1if(delcase==1){
        if(pred->left == curr) //if the node is a left child
            pred->left=NULL; //set pointer of its parentelse
            pred->right=NULL;
        delete(curr); //Return deleted node to the memory bank.
    }

    //Deletion Case 2if(delcase==2){
        if(pred->left==curr){ //if the node is a left childif(curr->left==NULL)
                pred->left=curr->right;
            else
                pred->left=curr->left;
        }
        else{ //pred->right=currif(curr->left==NULL)
                pred->right=curr->right;
            else
                pred->right=curr->left;
        }
        delete(curr);
    }

    //Deletion case 3if(delcase==3){
        succ = find_Insucc(curr); //Find the in_order successor//of the node.int item1 = succ->data;
        deleteNode(item1);  //Delete the inorder successor
        curr->data = item1; //Replace the data with the data of//in order successor.
    }
end:
}



void main(){
    BST obj;
    int choice;
    int height=0,total=0,n,item;
    node **tmp;

    while(1){
        clrscr();
        cout<<"*****BINARY SEARCH TREE OPERATIONS*****\n\n";
        cout<<"--Binary Tree and Binary Search Tree common operations--\n";
        cout<<"1) Create Tree\n";
        cout<<"2) Traversal\n";
        cout<<"3) Height of Tree\n";
        cout<<"4) Total Nodes\n";
        cout<<"5) Internal Nodes \n";
        cout<<"6) External Nodes \n";
        cout<<"7) Remove Tree\n";
        cout<<"\n--Only Binary Search Tree Operations--\n";
        cout<<"8)  Insert Node\n";
        cout<<"9)  Search Node\n";
        cout<<"10) Find Smallest Node\n";
        cout<<"11) Find Largest Node\n";
        cout<<"12) Delete Node\n";
        cout<<"13) Exit\n";
        cout<<"Enter your choice : ";
        cin>>choice;
        switch(choice){
            case 1 : //Create Tree
                cout<<"\n\n--Creating Tree--";
                cout<<"\nHow many nodes u want to enter : ";
                cin>>n;
                for(int i=0;i<n;i++){
                    cout<<"Enter value : ";
                    cin>>item;
                    obj.createTree(&obj.tree,item);
                }
                break;

            case 2 : //All Traversals
                cout<<"\n\nInorder Traversal : ";
                obj.inOrder(obj.tree);

                cout<<"\n\nPre-order Traversal : ";
                obj.preOrder(obj.tree);

                cout<<"\n\nPost-order Traversal : ";
                obj.postOrder(obj.tree);
                getch();
                break;

            case 3 : //Determining Height of Tree
                obj.determineHeight(obj.tree,&height);
                cout<<"\n\nHeight of Tree : "<<height;
                getch();
                break;

            case 4 : //Total nodes in a tree
                total=obj.totalNodes(obj.tree);
                cout<<"\n\nTotal Nodes : "<<total;
                getch();
                break;

            case 5 : //Internal nodes in a tree
                total=obj.internalNodes(obj.tree);
                cout<<"\n\nInternal Nodes : "<<total;
                getch();
                break;

            case 6 : //External nodes in a tree
                total=obj.externalNodes(obj.tree);
                cout<<"\n\nExternal Nodes : "<<total;
                getch();
                break;

            case 7 : //Remove Tree from memory
                obj.removeTree(&obj.tree);
                cout<<"\n\nTree is removed from Memory";
                getch();
                break;

            case 8 : //Inserting a node in a tree
                cout<<"\n\n--Inserting Node in a tree--\n";
                cout<<"Enter value : ";
                cin>>item;
                obj.createTree(&obj.tree,item);
                cout<<"\nItem is inserted\n";
                getch();
                break;

            case 9 : //Search element
                cout<<"\n\n--Search Element--\n";
                cout<<"Enter item to searched : ";
                cin>>item;
                &(*tmp) = obj.searchElement(&obj.tree,item);
                if( (*tmp) == NULL)
                    cout<<"\nSearch Element Not Found";
                else
                    cout<<"\nSearch Element was Found";
                getch();
                break;

            case 10 : //Find Smallest Node
                cout<<"\n\nSmallest Node is :  ";
                obj.findSmallestNode(obj.tree);
                getch();
                break;

            case 11 : //Find Largest Node
                cout<<"\n\nLargest Node is :  ";
                obj.findLargestNode(obj.tree);
                getch();
                break;

            case 12 : //Deleting a node from a tree
                cout<<"\n\n--Deleting a Node from a tree--\n";
                cout<<"Enter value : ";
                cin>>item;
                obj.deleteNode(item);
                break;

            case 13 : exit(1);
        }//end of switch
    }
}

Code for Program to maintain a threaded binary tree in C Programming

Code for Program to maintain a threaded binary tree in C Programming

 

#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 ;
    }
}

void deltree ( struct thtree **root )
{
    while ( ( *root ) -> left != *root )
        delete ( root, ( *root ) -> left -> data ) ;
}

Program to evaluate an expression entered in postfix form.

Program to evaluate an expression entered in postfix form.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>

#define MAX 50

struct postfix
{
    int stack[MAX] ;
    int top, nn ;
    char *s ;
} ;

void initpostfix ( struct postfix * ) ;
void setexpr ( struct postfix *, char * ) ;
void push ( struct postfix *, int ) ;
int pop ( struct postfix * ) ;
void calculate ( struct postfix * ) ;
void show ( struct postfix ) ;

void main( )
{
    struct postfix q ;
    char expr[MAX] ;

    clrscr( ) ;

    initpostfix ( &q ) ;


    printf ( "\nEnter postfix expression to be evaluated: " ) ;
    gets ( expr ) ;

    setexpr ( &q, expr ) ;
    calculate ( &q ) ;
    show ( q ) ;

    getch( ) ;
}

/* initializes data members */
void initpostfix ( struct postfix *p )
{
    p -> top = -1 ;
}

/* sets s to point to the given expr. */
void setexpr ( struct postfix *p, char *str )
{
    p -> s = str ;
}

/* adds digit to the stack */
void push ( struct postfix *p, int item )
{
    if ( p -> top == MAX - 1 )
        printf ( "\nStack is full." ) ;
    else
    {
        p -> top++ ;
        p -> stack[p -> top] = item ;
    }
}

/* pops digit from the stack */
int pop ( struct postfix *p )
{
    int data ;

    if ( p -> top == -1 )
    {
        printf ( "\nStack is empty." ) ;
            return NULL ;
    }

    data = p -> stack[p -> top] ;
    p -> top-- ;

    return data ;
}

/* evaluates the postfix expression */
void calculate( struct postfix *p )
{
    int n1, n2, n3 ;
    while ( *( p -> s ) )
    {
        /* skip whitespace, if any */
if ( *( p -> s ) == ' ' || *( p -> s ) == '\t' )
        {
            p -> s++ ;
            continue ;
        }

        /* if digit is encountered */
if ( isdigit ( *( p -> s ) ) )
        {
            p -> nn = *( p -> s ) - '0' ;
            push ( p, p -> nn ) ;
        }
        else
        {
            /* if operator is encountered */

            n1 = pop ( p ) ;
            n2 = pop ( p ) ;
            switch ( *( p -> s ) )
            {
                case'+' :
                      n3 = n2 + n1 ;
                      break ;

                case'-' :
                      n3 = n2 - n1 ;
                      break ;

                case'/' :
                      n3 = n2 / n1 ;
                      break ;

                case'*' :
                      n3 = n2 * n1 ;
                      break ;

                case'%' :
                      n3 = n2 % n1 ;
                      break ;

                case'$' :
                      n3 = pow ( n2 , n1 ) ;
                      break ;

                default :
                      printf ( "Unknown operator" ) ;
                      exit ( 1 ) ;
            }

            push ( p, n3 ) ;
        }
        p -> s++ ;
    }
}

/* displays the result */
void show ( struct postfix p )
{
    p.nn = pop ( &p ) ;
    printf ( "Result is: %d", p.nn ) ;
}

Code for Singly Linked list with following operations INSERT AT STARTING, INSERT AT MIDDLE, INSERT AT END, DELETE FIRST NODE, DELETE LAST NODE, DELETE MIDDLE in C Programming


Singly Linked list with below operations

1.CREATION
2.INSERT AT STARTING
3.INSERT AT MIDDLE(USER'S CHOICE)
4.INSERT AT END
5.DELETE 1ST NODE
6.DELETE LAST NODE
7.DELETE MIDDLE NODE(USER'S CHOICE)
8.DISPLAY 

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

struct node
{
    int i;
    struct node *next;
};

void main()
{

    struct node *first;
    struct node *last;

    struct node *temp;
    int ch,user,add,cnt=0,t=0;
    struct node *p;

    clrscr();

    printf("\n\t 1.CREATION");
    printf("\n\t 2.INSERT AT STARTING");
    printf("\n\t 3.INSERT AT MIDDLE(USER'S CHOICE)");
    printf("\n\t 4.INSERT AT END");
    printf("\n\t 5.DELETE 1ST NODE");
    printf("\n\t 6.DELETE LAST NODE");
    printf("\n\t 7.DELETE MIDDLE NODE(USER'S CHOICE)");
    printf("\n\t 8.DISPLAY");
    printf("\n\t 10.EXIT");
    scanf("%d",&user);

    while(user!=10)
    {
      if(user==1)
      {
        printf("\n\t ENTER DATA  ::: ");
        first=(struct node*)malloc(sizeof(struct node));
        scanf("%d",&ch);

        first->i=ch;
        first->next=0;
        p=first;
        cnt=1;
      }
      if(user==2)
      {
            p=(struct node*)malloc(sizeof(struct node));
            printf("\n\t ENTER DATA FOR 1ST NODE");
            scanf("%d",&p->i);
            p->next=first;
            first=p;
            cnt++;
      }
      if(user==4)
      {
            p=(struct node*)malloc(sizeof(struct node));
            printf("\n\t ENTER DATA FOR LAST NODE");
            scanf("%d",&p->i);
            temp=first;
            while(temp->next!=0)
            {
                temp=temp->next;
            }
            temp->next=p;
            p->next=0;
            cnt++;
      }
      if(user==3)
      {
            printf("\n\t ENTER ANY ADDRESS BETWEEN 1 and %d",cnt);
            scanf("%d",&add);

            t=1;
            p=first;
            while(t!=add)
            {
                p=p->next;
                t++;
            }
            temp=(struct node*)malloc(sizeof(struct node));
            printf("\n\t ENTER DATA FOR NODE");
            scanf("%d",&temp->i);
            temp->next=p->next;
            p->next=temp;
            cnt++;
      }
      if(user==5)
      {
            p=first;
            first=p->next;
            free(p);
      }
      if(user==6)
      {
        p=first;
        while(p->next->next!=0)
        {
            p=p->next;
        }
        p->next=0;
        free(p->next->next);
      }
      if(user==8)
      {
        p=first;
        while(p!=0)
        {
            printf("\n\t %d",p->i);
            p=p->next;
        }
      }
      if(user==7)
      {
            printf("\n\t ENTER ANY ADDRESS BETWEEN 1 and %d",cnt);
            scanf("%d",&add);

            t=1;
            p=first;
            while(t<add-1)
            {
                p=p->next;
                t++;
            }
            temp=p->next;
            p->next=temp->next;
            free(temp);
            cnt--;

      }
      printf("\n\t 1.CREATION");
      printf("\n\t 2.INSERT AT STARTING");
      printf("\n\t 3.INSERT AT MIDDLE(USER'S CHOICE)");
      printf("\n\t 4.INSERT AT END");
      printf("\n\t 5.DELETE 1ST NODE");
      printf("\n\t 6.DELETE LAST NODE");
      printf("\n\t 7.DELETE MIDDLE NODE(USER'S CHOICE)");
      printf("\n\t 8.DISPLAY");
      printf("\n\t 10.EXIT");
      scanf("%d",&user);
       }
       getch();
}

Practical no-10


Practical no-10

#!/bin/bash
echo "1. all user list"
echo "2.current user"
echo "3.count logged users"
printf "Enter choice:"read choice
if [$choice==1];
then
Who -h
Fi

if [$choice==2];
then
who am i
fi

if [$choice==3];
then
echo "Total users loged in:"
fi

OUTPUT
***********

[root@LINTEL]$ sh user.sh
1. all user list
2. current user
3. count logged user
Enter choice:2
Root