Friday, October 29, 2010

STACK - LINKED LIST IMPLEMENTATION



In computer science, a stack is a last in, first out (LIFO) abstract data type and data structure. A stack can have any abstract data type as an element, but is characterized by only two fundamental operations: push and pop. The push operation adds to the top of the list, hiding any items already on the stack, or initializing the stack if it is empty. The pop operation removes an item from the top of the list, and returns this value to the caller. A pop either reveals previously concealed items, or results in an empty list.

A stack is a restricted data structure, because only a small number of operations are performed on it. The nature of the pop and push operations also means that stack elements have a natural order. Elements are removed from the stack in the reverse order to the order of their addition: therefore, the lower elements are typically those that have been in the list the longest.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN STACK -LINKED LIST IMPLEMENTATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :3 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
#include
int DATA;

struct NODE
{
int DATA;
struct NODE *LINK;
};
struct NODE *TOP=NULL,*TEMP;
int main()
{
int CH,OPT;

do//infinite loop is used to insert/delete infinite number of nodes
{
printf("\n STACK OPERATIONS BY DEPLOYMENT OF LINKED LIST...");
printf("\n\n MENU:");
printf("\n[1].PUSH ELEMENT");
printf("\n[2].POP ELEMENT");
printf("\n[3].DISPLAY");
printf("\n[4].EXIT");
printf("\n\n OPTION:");
scanf("%d",&CH);
switch(CH)
{
case 1:
printf("\n\n PUSH OPERATION INVOKED...");
PUSH();
break;
case 2:
printf("\n\n POP OPERATION INVOKED...");
POP();
break;

case 3:
printf("\n\n TRAVERSAL OPERATION INVOKED...");
DISPLAY();
break;
case 4:
exit(0);
}
printf("\n\n DO YOU WISH TO CONTINUE:1~0:");
scanf("%d" ,&OPT);
}while(OPT==1);
printf("\n TERMINATING OPERATION...");
system("pause");

return 0;
}
int PUSH()
{
TEMP=(struct NODE *)malloc(sizeof(struct NODE));
printf("\n ENTER DATA:");
scanf("%d",&DATA);
TEMP->DATA=DATA;
TEMP->LINK=TOP;
TOP=TEMP;
printf("\nPUSHING DATA INTO STACK...");
printf("\n\nPUSHING OPERATION COMPLETED SUCCESSFULLY...");
}

int POP()
{
if(TOP!=NULL)
{
printf("\n THE DATA POPPED FROM STACK: %d",TOP->DATA);
TOP=TOP->LINK;
}
else
{
printf("\n ERROR!!! STACK UNDERFLOW...");
}
printf("\nPOPPING DATA INTO STACK...");
printf("\n\nPOPPING OPERATION COMPLETED SUCCESSFULLY...");
}

int DISPLAY()
{
int S=1;
TEMP=TOP;
if(TEMP==NULL)
{
printf("\nERROR!!! STACK IS EMPTY...");
}

while(TEMP!=NULL)
{

printf("\n|ELEMENT %d:%d|",S,TEMP->DATA);
printf("\n^^^^^^^^^^^^^^^^");
TEMP=TEMP->LINK;
S++;
}

}


----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

QUEUE - ARRAY IMPLEMENTATION



A queue (pronounced /kjuː/) is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.

Queues provide services in computer science, transport, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.

Queues are common in computer programs, where they are implemented as data structures coupled with access routines, as an abstract data structure or in object-oriented languages as classes. Common implementations are circular buffers and linked lists.


Theoretically, one characteristic of a queue is that it does not have a specific capacity. Regardless of how many elements are already contained, a new element can always be added. It can also be empty, at which point removing an element will be impossible until a new element has been added again.

A practical implementation of a queue, e.g. with pointers, of course does have some capacity limit, that depends on the concrete situation it is used in. For a data structure the executing computer will eventually run out of memory, thus limiting the queue size. Queue overflow results from trying to add an element onto a full queue and queue underflow happens when trying to remove an element from an empty queue.

A bounded queue is a queue limited to a fixed number of items.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN QUEUE-ARRAY IMPLEMENTATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
# define MAXSIZE 200

int QUEUE[MAXSIZE];
int FRONT, REAR;
int main()
{
void ENQ(int);
int DEQ();
int CH,OPT,i,num;
FRONT =0;
REAR = 0;


do
{
printf("\n QUEUE OPERATIONS BY IMPLEMENTATION OF ARRAYS");
printf("\n\n MAIN MENU:");
printf("\n[1].ENQUEUE DATA");
printf("\n[2].DEQUEUE DATA");
printf("\n[3].TRAVERSAL");
printf("\n\n OPTION:");
scanf("%d",&CH);

switch(CH)
{
case 1:
printf("\n\nQUEUE OPERATION INVOKED...");
printf("\nENTER DATA: ");
scanf("%d",&num);
ENQ(num);
break;
case 2:
i=DEQ();
printf("\n DEQUEUE OPERATION RESULT:%d ",i);
break;

case 3:
printf("\n\n TRAVERSAL OPERATION INVOKED...");
DISPLAY();
break;
default:
printf("\n\n INVALID CHOICE ... ");
break;
}
printf("\n\n DO YOU WISH TO CONTINUE:1~0:");
scanf("%d",&OPT);
}while(OPT==1);
printf("\n TERMINATING PROCESS...");
system("pause");
return 0;
}

//end of main

void ENQ(int a)
{

if(REAR>MAXSIZE)
{
printf("\nERROR!!! QUEUE FULL");
return;
}
else
{
QUEUE[REAR]=a;
REAR++;
printf("\n\n REAR : %d & FRONT :%d",REAR,FRONT);
}
}

int DEQ()
{
int a;
if(FRONT == REAR)
{
printf("\n\n QUEUE EMPTY");
return(0);
}
else
{
a=QUEUE[FRONT];
FRONT++;
}
return(a);
}
int DISPLAY()
{

int i=0,j=1;
if(REAR>=0)
{

printf("\n\n TRAVERSING QUEUE...");
while(i


----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

QUEUE -LINKED LIST IMPLEMENTATION


A queue (pronounced /kjuː/) is a particular kind of collection in which the entities in the collection are kept in order and the principal (or only) operations on the collection are the addition of entities to the rear terminal position and removal of entities from the front terminal position. This makes the queue a First-In-First-Out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed. This is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked. A queue is an example of a linear data structure.

Queues provide services in computer science, transport, and operations research where various entities such as data, objects, persons, or events are stored and held to be processed later. In these contexts, the queue performs the function of a buffer.

Queues are common in computer programs, where they are implemented as data structures coupled with access routines, as an abstract data structure or in object-oriented languages as classes. Common implementations are circular buffers and linked lists.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN QUEUE -LINKED LIST DEPLOYMENT

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :3 kb

EXE FILE SIZE :23 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
#include
#include
//STRUCTURE DEFINITION
struct LIST
{
int DATA;
struct LIST *NEXT;
};
/***** Redefining struct LIST as NODE *****/
typedef struct LIST NODE;
void ENQUEUE(NODE**,NODE**); /** Inserting character function in queue **/
void DEQUEUE(NODE**,NODE**); /** Deleting character function in queue **/
void DISPLAY(NODE*); /** Output displaying function **/



int main()
{
int OPT; /* Option inputing variable */
char ch; /* choice inputing variable */
NODE *FRONT; /* FRONT pointer in queue*/
NODE *REAR; /* REAR pointer in queue */
REAR=FRONT=NULL;
do
{
printf("\n QUEUE OPERATIONS BY DEPLOYMENT OF LINKED LISTS...");
printf("\n\n MENU:");
printf("\n[1].ENQUEUE DATA.");
printf("\n[2].DEQUEUE DATA. ");
printf("\n[3].TRAVERE QUEUE.");
printf("\n\n ENTER OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\n\n ENQUEUE OPERATION INVOKED...");
ENQUEUE(&FRONT,&REAR);
printf("\n\n ELEMENT ENQUEUED SUCCESSFULLY ...");
break;
case 2:
printf("\n\n DEQUEUE OPERATION INVOKED...");
DEQUEUE(&FRONT,&REAR);
printf("\n\n ELEMENT DEQUEUED SUCCESSFULLY ...");
break;
case 3:
printf("\n\n TRAVERSAL OPERATION INVOKED...");
DISPLAY(FRONT);
break;
}
printf("\n DO YOU WISH TO CONTINUE[y/n]:");
ch=(char)getche();
}while(ch=='Y' || ch=='y');

system("pause");
return 0;
}

void ENQUEUE(NODE **FRONT,NODE **REAR)
{
NODE *NEW; /* New NODE to be inserted */
NEW=(NODE*)malloc(sizeof(NODE));
NEW->NEXT=NULL;
printf("\n ENTER DATA TO ENQUEUE:");

scanf("%d",&(NEW->DATA));
if(*FRONT==NULL && *REAR==NULL)
{
*FRONT=NEW;
*REAR=NEW;
}
else
{

(*REAR)->NEXT=NEW;
*REAR=NEW;
}
}

void DEQUEUE(NODE **FRONT,NODE **REAR)
{
NODE *delnode; /* Node to be deleted */
if((*FRONT)==NULL && (*REAR)==NULL)
printf("\n ERROR!!!QUEUE IS EMPTY");
else
{
delnode=*FRONT;
(*FRONT)=(*FRONT)->NEXT;
free(delnode);
}
}
void DISPLAY(NODE *f)
{
int S=1;
while(f!=NULL)
{
printf("ELE%d:%d",S,f->DATA);
printf("<-");
f=f->NEXT;
S++;
}
}


----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

CIRCULAR QUEUE-LINKED LIST



A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams.

An example that could possibly use an overwriting circular buffer is with multimedia. If the buffer is used as the bounded buffer in the producer-consumer problem then it is probably desired for the producer (e.g., an audio generator) to overwrite old data if the consumer (e.g., the sound card) is unable to momentarily keep up. Another example is the digital waveguide synthesis method which uses circular buffers to efficiently simulate the sound of vibrating strings or wind instruments.

The "prized" attribute of a circular buffer is that it does not need to have its elements shuffled around when one is consumed. (If a non-circular buffer were used then it would be necessary to shift all elements when one is consumed.) In other words, the circular buffer is well suited as a FIFO buffer while a standard, non-circular buffer is well suited as a LIFO buffer.


----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN CIRCULAR QUEUE -LINKED LIST

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
int ISFULL();
int ISEMPTY();
void ENQUEUE(int);
int DEQUEUE();

struct QUEUE
{
int ELE;
struct QUEUE *NEXT;
};

struct QUEUE *TEMP,*P,*FRONT,*REAR;
void INIT()
{
TEMP=NULL;
P=NULL;
FRONT=NULL;
REAR=NULL;
}

int main()
{
INIT();
int CH,OPT,EL;
do
{
printf("\n CIRCULAR QUEUE USING LINKED LIST IMPLEMENTATION");
printf("\n\n MENU:");
printf("\n [1]. ENQUEUE");
printf("\n [2]. DEQUEUE");
printf("\n [3].EXIT");
printf("\n\n OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\n ENQUEUE PROCESS INVOKED...");
if(ISFULL())
{
printf("\n QUEUE IS FULL");
break;
}
printf("\n\n ENTER AN ELEMENT:");
scanf("%d",&EL);
ENQUEUE(EL);
break;

case 2:
printf("\n DEQUEUE PROCESS INVOKED...");
if(ISEMPTY())
{
printf("\n QUEUE IS EMPTY");
break;
}
EL=DEQUEUE();
printf("\n ELEMENT DEQUEUED:%d",EL);
break;

case 3:
printf("\n\n TERMINATING....");
break;

default:
printf("\n\n INVALID OPTION");
break;
}
printf("\n DO YOU WISH TO CONTINUE?1~0:");
scanf("%d",&CH);
}while(CH==1);
return 0;
}

void ENQUEUE(int ELE)
{
P->NEXT=NULL;
P->ELE=ELE;
if(FRONT==NULL)
{
FRONT=P;
REAR=P;
return ;
}
REAR->NEXT=P;
REAR=P;
REAR->NEXT=FRONT;
}

int DEQUEUE()
{
int ELE;
ELE=FRONT->ELE;
TEMP=FRONT;
if(FRONT==REAR)
{
INIT();
}
else
{
FRONT=FRONT->NEXT;
REAR->NEXT=FRONT;
}
free (TEMP);
return ELE;
}


int ISEMPTY()
{
if (FRONT==NULL)
return 1;
else
return 0;
}

int ISFULL()
{
P=(struct QUEUE *)malloc (sizeof(struct QUEUE));
if (P==NULL)
return 1;
else
return 0;
}

----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

INFIX TO POSTFIX EXPRESSION CONVERSION - STACK APPLICATION



Edsger Dijkstra invented the Shunting-yard algorithm to convert infix expressions to postfix (RPN), so named because its operation resembles that of a railroad shunting yard.

There are other ways of producing postfix expressions from infix notation. Most Operator-precedence parsers can be modified to produce postfix expressions; in particular, once an abstract syntax tree has been constructed, the corresponding postfix expression is given by a simple post-order traversal of that tree.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT INFIX TO POSTFIX EXPRESSION CONVERSION - STACK APPLICATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :3 kb

EXE FILE SIZE :23 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
#include
#define SIZE 10
char STACK[SIZE];
int TOP=0,ELE;
void PUSH();
char POP();
void SHOW();
int ISEMPTY();
int ISFULL();
char INFIX[30],OUTPUT[30];
int prec(char);

int main()
{
int i=0,j=0,k=0,LENGTH;
char TEMP;
printf("\n CONVERSION OF INFIX TO POSTFIX EXPRESSION");
printf("\n\n ENTER AN INFIX EXPRESSION:");
scanf("%s",INFIX);
printf("\n INFIX EXPRESSION:\t %s",INFIX);
LENGTH=strlen(INFIX);
for(i=0;i {
//Numbers are added to the out put QUE
if(INFIX[i]!='+' && INFIX[i]!='-' && INFIX[i]!='*' && INFIX[i]!='/' && INFIX[i]!='^' && INFIX[i]!=')' && INFIX[i]!='(' )
{
OUTPUT[j++]=INFIX[i];
printf("\nTHE ELEMENT ADDED TO QUEUE:%c",INFIX[i]);
}
//If an operator or a bracket is encountered...
else
{
if(TOP==0) //If there are no elements in the STACK, the operator is added to it
{
PUSH(INFIX[i]);
printf("\nELEMENT PUSHED:%c",INFIX[i]);
}
else
{ //Operators or pushed or poped based on the order of precedence
if(INFIX[i]!=')' && INFIX[i]!='(')
{
if( prec(INFIX[i]) <= prec(STACK[TOP-1]) )
{
TEMP=POP();
printf("\n POPPED ELEMENT:%c",TEMP);
OUTPUT[j++]=TEMP;
PUSH(INFIX[i]);
printf("\n PUSHED ELEMENT:%c",INFIX[i]);
SHOW();
}
else
{
PUSH(INFIX[i]);
printf("\n INFIX EXPRESSION:%c",INFIX[i]);
SHOW();
}
}
else
{
if(INFIX[i]=='(')
{
PUSH(INFIX[i]);
printf("\nPUSHED ELEMENT:%c",INFIX[i]);
}
if(INFIX[i]==')')
{
TEMP=POP();
while(TEMP!='(')
{OUTPUT[j++]=TEMP;
printf("\n ELEMENT ADDED TO QUEUE:%c",TEMP);
//TEMP=POP();
printf("\n POPPED ELEMENT:%c",TEMP);
TEMP=POP();}
}
}

}

}

printf("\n INFIX EXPRESSION:%s",OUTPUT);

}
while(TOP!=0)
{
OUTPUT[j++]=POP();
}
printf("\n INFIX EXPRESSION: %s\n",OUTPUT);
system("pause");
return 0;
}
//Functions for operations on STACK
void PUSH(int ELE)
{
STACK[TOP]=ELE;
TOP++;
}
char POP()
{
TOP--;
return(STACK[TOP]);
}
void SHOW()
{
int x=TOP;
printf("STACK ELEMENTS:");
while(x!=0)
printf("%c, ",STACK[--x]);
}
//Function to get the precedence of an operator
int prec(char symbol)
{

if(symbol== '(')
return 0;
if(symbol== ')')
return 0;
if(symbol=='+' || symbol=='-')
return 1;
if(symbol=='*' || symbol=='/')
return 2;
if(symbol=='^')
return 3;
return 0;
}

----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

EVALUATION OF POSTFIX EXPRESSION-STACK APPLICATION



Reverse Polish notation (or RPN) is a mathematical notation wherein every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position. It is also known as Postfix notation and is parenthesis-free as long as operator arities are fixed. The description "Polish" refers to the nationality of logician Jan Łukasiewicz, who invented (prefix) Polish notation in 1920s.

The Reverse Polish scheme was proposed in 1954 by Burks, Warren, and was independently reinvented by F. L. Bauer and E. W. Dijkstra in the early 1960s to reduce computer memory access and utilize the stack to evaluate expressions. The notation and algorithms for this scheme were extended by Australian philosopher and computer scientist Charles Hamblin in the mid-1950s.

During the 1970s and 1980s, RPN had some currency even among the general public, as it was widely used in handheld calculators of the time – for example, the HP-10C series and Sinclair Scientific calculators.

In computer science, postfix notation is often used in stack-based and concatenative programming languages. It is also common in dataflow and pipeline-based systems, including Unix pipelines.

Most of what follows is about binary operators. A unary operator for which the Reverse Polish notation is the general convention is the factorial

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT EVALUATION OF POSTFIX EXPRESSION -STACK

APPLICATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:


# include

typedef struct
{
int A[100];
int TOP;
}STACK;

void PUSH(STACK *S,int X)
{
if(S->TOP==99)
printf("\n\n ERROR!!!! STACK OVERFLOW\n");
else
S->A[++S->TOP]=X;
}

int POP(STACK *S)
{
int X;
if(S->TOP<0) x="S-">A[S->TOP--];
return X;
}
}

int OPERATION(int P1,int P2,char OP)
{
switch(OP)
{
case '+':return P1+P2;
case '*':return P1*P2;
case '-':return P1-P2;
case '/':return P1/P2;
}
}

int EVALUATE(char pos[])
{
STACK S1;
int P1,P2,result,i;
S1.TOP=-1;
for(i=0;pos[i]!='\0';i++)
if(isdigit(pos[i]))
PUSH(&S1,pos[i]-'0');/*use to find the integer value of it*/
else
{
P2=POP(&S1);
P1=POP(&S1);
result=OPERATION(P1,P2,pos[i]);
PUSH(&S1,result);
}/*end of for loop*/
return POP(&S1);
}

int main()
{
char POSTFIX[100];
printf("\n EVALUATIO OF POST FIX EXPRESSIONS");
printf("\n\n NOTE: \n [1].ENTER A VALID POSTFIX STRING \n\n [2].OPERANDS ARE SINGLE DIGIT\n\n");
gets(POSTFIX);
printf("RESULT:%d",EVALUATE(POSTFIX));
system("pause");
return 0;

}
/*end of main*/


---------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

SYMBOL BALANCING/ SYNTAX PARSING -APPLICATIONS OF STACK



In computer science and linguistics, parsing, or, more formally, syntactic analysis, is the process of analyzing a text, made of a sequence of tokens (for example, words), to determine its grammatical structure with respect to a given (more or less) formal grammar. Parsing can also be used as a linguistic term, especially in reference to how phrases are divided up in garden path sentences.

Parsing is also an earlier term for the diagramming of sentences of natural languages, and is still used for the diagramming of inflected languages, such as the Romance languages or Latin. The term parsing comes from Latin pars (ōrātiōnis), meaning part (of speech).

Parsing is a common term used in psycholinguistics when describing language comprehension. In this context, parsing refers to the way that human beings, rather than computers, analyze a sentence or phrase (in spoken language or text) "in terms of grammatical constituents, identifying the parts of speech, syntactic relations, etc." This term is especially common when discussing what linguistic cues help speakers to parse garden-path sentences.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT SYMBOL BALANCING-STACK APPLICATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
#include
#define VALID 1
#define INVALID 0
#define SIZE 30
char stack[SIZE];
int top=-1;
int check(char[]);
void push(char);
int pop();
int main()
{
char expr[30];
int status;
printf("\n BALANCING OF SYMBOLS-IMPLEMENTATION OF STACK");
printf("\n\n\n ENTER EXPRESSION:");
scanf("%s",expr);
status=check(expr);
printf("\n\n\n %s",(status)?" EXPRESSION IS VALID":"ERROR!!!! EXPRESSION IS INVALID");
printf("\n\n");
system("pause");
return 0;
}
int check(char expr[])
{
char open[]={'(','{','['};
char close[]={')','}',']'};
int i,j,len,item,nop=3;
len=strlen(expr);
for(i=0;i
{
for(j=0;j
{
if(expr[i]==open[j])
{
push(expr[i]);
}
if(expr[i]==close[j])
{
item=pop();
if(item==-1||item!=open[j])
return INVALID;
}
}
}
if(top!=-1)
return INVALID;
else
return VALID;
}
void push(char val)
{
if(top>=SIZE-1)
{
printf("\nERROR!!!! STACK IS FULL....");
exit(0);
}
stack[++top]=val;
}
int pop()
{
int val;
if(top<=-1)
return -1;
val=stack[top--];
return val;
}



----------------------------------------------------------------------------------------------

Your's friendly,
[MOHANRAM.G],
ADMIN...

BINARY SEARCH TREE



In computer science, a binary search tree (BST) or ordered binary tree is a node-based binary tree data structure which has the following properties:

  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • Both the left and right subtrees must also be binary search trees.

Generally, the information represented by each node is a record rather than a single data element. However, for sequencing purposes, nodes are compared according to their keys rather than any part of their associated records.

The major advantage of binary search trees over other data structures is that the related sorting algorithms and search algorithms such as in-order traversal can be very efficient.

Binary search trees are a fundamental data structure used to construct more abstract data structures such as sets, multisets, and associative arrays.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN BINARY SEARCH TREE

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
typedef struct treenode *searchtree;
typedef struct treenode *position;
struct treenode
{
int dat;
searchtree left,right;
}*t;
searchtree makeempty(searchtree t)
{
if(t!=NULL)
{
makeempty(t->left);
makeempty(t->right);
free(t);
}
return NULL;
}
position find(int a, searchtree t)
{
if(t==NULL)
return NULL;
if(adat)
return find(a,t->left);
else
if(a>t->dat)
return find(a,t->right);
else
return t;
}
position findmin(searchtree t)
{
if(t==NULL)
return NULL;
else
if(t->left==NULL)
return t;
else
return findmin(t->left);
}
position findmax(searchtree t)
{
if(t==NULL)
return NULL;
else
if(t->right==NULL)
return t;
else
findmax(t->right);
}
searchtree insert(int a, searchtree t)
{
if(t==NULL)
{
t=malloc(sizeof(struct treenode));
t->dat=a;
t->left=t->right=NULL;
}
else
{
if(adat)
t->left= insert(a,t->left);
else
if(a>t->dat)
t->right=insert(a,t->right);
}
return t;
}
searchtree delete(int a,searchtree t)
{
position tmpcell;
if(t==NULL)
printf("element not present");
else
if(adat)
t->left=delete(a,t->left);
else
if(a>t->dat)
t->right=delete(a,t->right);
else
if(t->left&&t->right)
{
tmpcell=findmin(t->right);
t->dat=tmpcell->dat;
t->right=delete(t->dat,t->right);
}
else
{
tmpcell=t;
if(t->left==NULL)
t=t->right;
else
if(t->right==NULL)
t=t->left;
free(tmpcell);
}
return t;
}

void disp()
{
struct treenode *temp;
printf("\t%d",t->dat);
temp=t->left;
while(temp!=NULL)
{
printf("\n%d",temp->dat);
temp=temp->left;
}
temp=t->right;;
while(temp!=NULL)
{
printf("\n\t\t%d",temp->dat);
temp=temp->right;
}}

int main()
{
int OPT,CH,a;
struct treenode *temp;
t=NULL;
temp=makeempty(t);
do
{
printf("\n BINARY SEARCH TREE LINKED LIST IMPLEMENTATION");
printf("\n\n MENU:");
printf("\n [1].INSERTION");
printf("\n [2].DELETION");
printf("\n [3].DISPLAY");
printf("\n [4].SEARCH");
printf("\n [5].EXIT");
printf("\n\n OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\nINSERTION PROCESS INVOKED...");
printf("\nENTER ELEMENT:");
scanf("%d",&a);
t=insert(a,t);
disp();
break;
case 2:
printf("\nDELETION PROCESS INVOKED...");
printf("\nENTER ELEMENTS TO DELETE");
scanf("%d",&a);
t=delete(a,t);
disp();
break;
case 3:
printf("\nDISPLAY PROCESS INVOKED...");
printf("\nTHE ELEMENTS:");
disp();
break;
case 4:
printf("\nSEARCH PROCESS INVOKED...");
printf("\nENTER DATA :");
scanf("%d",&a);
temp=find(a,t);
if(temp!=NULL)
printf("\n ELEMENT NOT FOUND");
else
printf("\n ELEMENT NOT FOUND");
break;
default:
printf("\nTERMINATING...");
break;
}
printf("\n DO YOU WISH TO CONTINUE?1~0:");
scanf("%d",&CH);
}while(CH==1);
system("pause");
return 0;
}

----------------------------------------------------------------------------------------------
Your's friendly,

[MOHANRAM.G],
ADMIN...

AVL TREE



In computer science, an AVL tree is a self-balancing binary search tree, and it was the first such data structure to be invented. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; therefore, it is also said to be height-balanced. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases, where n is the number of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.

The AVL tree is named after its two inventors, G.M. Adelson-Velskii and E.M. Landis, who published it in their 1962 paper "An algorithm for the organization of information."

The balance factor of a node is the height of its left subtree minus the height of its right subtree (sometimes opposite) and a node with balance factor 1, 0, or −1 is considered balanced. A node with any other balance factor is considered unbalanced and requires rebalancing the tree. The balance factor is either stored directly at each node or computed from the heights of the subtrees.

AVL trees are often compared with red-black trees because they support the same set of operations and because red-black trees also take O(log n) time for the basic operations. AVL trees perform better than red-black trees for lookup-intensive applications. The AVL tree balancing algorithm appears in many computer science curricula.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN AVL TREE

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :5 kb

EXE FILE SIZE :4 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include

typedef enum { FALSE ,TRUE } bool;
struct node
{
int info;
int balance;
struct node *lchild;
struct node *rchild;
};

struct node *insert (int , struct node *, int *);
struct node* search(struct node *,int);

main()
{
bool ht_inc;
int info ;
int OPT,CH;
struct node *root = (struct node *)malloc(sizeof(struct node));
root = NULL;


do
{
printf("\n AVL OPERATIONS BY DEPLOYMENT OF LINKED LISTS...");
printf("\n\n MENU:");
printf("\n[1].INSERT");
printf("\n[2].DISPLAY");
printf("\n[3].QUIT");
printf("\n\n ENTER OPTION:");
scanf("%d",&OPT);
switch(OPT)
{
case 1:
printf("\nINSERTION PROCESS INVOKED...");
printf("\n ENTER ELEMENT: ");
scanf("%d", &info);
if( search(root,info) == NULL )
root = insert(info, root, &ht_inc);
else
printf("\n DUPLICATE VALUE IGNORED...");
break;

case 2:
printf("\n DELETION PROCESS INVOKED...");
if(root==NULL)
{
printf("\nERROR!!!!! TREE IS EMPTY...");
continue;
}
printf("\nTREE :");
display(root, 1);
printf("\n\n");
printf("\nINORDER TRAVERSAL:");
inorder(root);
printf("\n");
break;

case 3:
exit(1);
default:
printf("\nINVALID CHOICE..");
}
printf("\n DO YOU WISH TO CONTINUE?1~0:");
scanf("%d",&CH);
}while(CH==1);
system("pause");
return 0;
}

struct node* search(struct node *ptr,int info)
{
if(ptr!=NULL)
if(info <>info)
ptr=search(ptr->lchild,info);
else if( info > ptr->info)
ptr=search(ptr->rchild,info);
return(ptr);
}/*End of search()*/

struct node *insert (int info, struct node *pptr, int *ht_inc)
{
struct node *aptr;
struct node *bptr;

if(pptr==NULL)
{
pptr = (struct node *) malloc(sizeof(struct node));
pptr->info = info;
pptr->lchild = NULL;
pptr->rchild = NULL;
pptr->balance = 0;
*ht_inc = TRUE;
return (pptr);
}

if(info <>info)
{
pptr->lchild = insert(info, pptr->lchild, ht_inc);
if(*ht_inc==TRUE)
{
switch(pptr->balance)
{
case -1: /* Right heavy */
pptr->balance = 0;
*ht_inc = FALSE;
break;
case 0: /* Balanced */
pptr->balance = 1;
break;
case 1: /* Left heavy */
aptr = pptr->lchild;
if(aptr->balance == 1)
{
printf("Left to Left Rotation\n");
pptr->lchild= aptr->rchild;
aptr->rchild = pptr;
pptr->balance = 0;
aptr->balance=0;
pptr = aptr;
}
else
{
printf("Left to right rotation\n");
bptr = aptr->rchild;
aptr->rchild = bptr->lchild;
bptr->lchild = aptr;
pptr->lchild = bptr->rchild;
bptr->rchild = pptr;

if(bptr->balance == 1 )
pptr->balance = -1;
else
pptr->balance = 0;
if(bptr->balance == -1)
aptr->balance = 1;
else
aptr->balance = 0;
bptr->balance=0;
pptr=bptr;
}
*ht_inc = FALSE;
}/*End of switch */
}/*End of if */
}/*End of if*/

if(info > pptr->info)
{
pptr->rchild = insert(info, pptr->rchild, ht_inc);
if(*ht_inc==TRUE)
{
switch(pptr->balance)
{
case 1: /* Left heavy */
pptr->balance = 0;
*ht_inc = FALSE;
break;
case 0: /* Balanced */
pptr->balance = -1;
break;
case -1: /* Right heavy */
aptr = pptr->rchild;
if(aptr->balance == -1)
{
printf("Right to Right Rotation\n");
pptr->rchild= aptr->lchild;
aptr->lchild = pptr;
pptr->balance = 0;
aptr->balance=0;
pptr = aptr;
}
else
{
printf("Right to Left Rotation\n");
bptr = aptr->lchild;
aptr->lchild = bptr->rchild;
bptr->rchild = aptr;
pptr->rchild = bptr->lchild;
bptr->lchild = pptr;

if(bptr->balance == -1)
pptr->balance = 1;
else
pptr->balance = 0;
if(bptr->balance == 1)
aptr->balance = -1;
else
aptr->balance = 0;
bptr->balance=0;
pptr = bptr;
}/*End of else*/
*ht_inc = FALSE;
}/*End of switch */
}/*End of if*/
}/*End of if*/

return(pptr);
}/*End of insert()*/

display(struct node *ptr,int level)
{
int i;
if ( ptr!=NULL )
{
display(ptr->rchild, level+1);
printf("\n");
for (i = 0; i <>info);
display(ptr->lchild, level+1);
}/*End of if*/
}/*End of display()*/

inorder(struct node *ptr)
{
if(ptr!=NULL)
{
inorder(ptr->lchild);
printf("%d ",ptr->info);
inorder(ptr->rchild);
}
}/*End of inorder()*/

----------------------------------------------------------------------------------------------

Your's friendly,
[MOHANRAM.G],
ADMIN...

BINARY HEAP



A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints:
  • The shape property: the tree is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
  • The heap property: each node is greater than or equal to each of its children according to some comparison predicate which is fixed for the entire data structure.

"Greater than or equal to" means according to whatever comparison function is chosen to sort the heap, not necessarily "greater than or equal to" in the mathematical sense (since the quantities are not always numerical). Heaps where the comparison function is mathematical "greater than or equal to" are called max-heaps; those where the comparison function is mathematical "less than" are called "min-heaps". Conventionally, min-heaps are used, since they are readily applicable for use in priority queues.

Note that the ordering of siblings in a heap is not specified by the heap property, so the two children of a parent can be freely interchanged, as long as this does not violate the shape and heap properties (compare with treap).

The binary heap is a special case of the d-ary heap in which d = 2.

It is possible to modify the heap structure to allow extraction of both the smallest and largest element in O(logn) time. To do this, the rows alternate between min heap and max heap. The algorithms are roughly the same, but, in each step, one must consider the alternating rows with alternating comparisons. The performance is roughly the same as a normal single direction heap. This idea can be generalised to a min-max-median heap.

----------------------------------------------------------------------------------------------

A C PROGRAM TO IMPLEMENT OPERATIONS IN BINARY HEAP

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :2 kb

EXE FILE SIZE :22 kb

NOTE: PLEASE INCLUDE THE DESIRED HEADER FILE

---------------------------------------------------------------------------------------------

C PROGRAM SOURCE & EXE DOWNLOAD:

Click download button to download

DISCLAIMER: The following program cannot be ensured of perfection.so any flaws in the program can be notified in the comments section.

----------------------------------------------------------------------------------------------

CODE:

#include
int heap[10],min,last,h=0;
void insert();
void deletemin();
void display();
int main()
{
int CH,OPT;

do
{

printf("\n BINARY HEAP-ARRAY IMPLEMENTATION");
printf("\n\n NOTE:ARRAY MAXIMUM SIZE DEFINED:10");
printf("\n\n MENU:");
printf("\n [1].INSERT");
printf("\n [2].DELETEMIN");
printf("\n [3].DISPLAY");
printf("\n [4].EXIT");
printf("\n\n OPTION:");
scanf("%d",&OPT);

switch(OPT)
{
case 1:
insert();
break;

case 2:
deletemin();
break;

case 3:
display();
break;

case 4:
break;


}
printf("\n DO YOU WISH TO CONTINUE?1~0:");
scanf("%d",&CH);
}while(CH==1);
printf("\n\n");
system("pause");
return 0;
}

void insert()
{
int i,x;
printf("\nINSERTION MECHANISM LAUNCHED");
if( h>9)
printf("\n HEAP IS FULL");
else
{
h++;
printf("\n ENTER ELEMENT TO BE INSERTED:");
scanf("%d",&x);
for(i=h;heap[i/2]>x;i=i/2)
{
heap[i]=heap[i/2];
}
heap[i]=x;
}
}

void deletemin()
{
int i,child;
if(h==0)
printf("\n\n HEAP IS EMPTY...");
else
{
min=heap[i];
last=heap[h];
h--;
for(i=1;i*2<=h;i=child) { child=i*2; if(child!=h&&heap[child-1]heap[child])
heap[i]=heap[child];
else
break;
}
heap[i]=0;
}
printf("\n MINIMUM ELEMENT DELETED SUCCESSFULLY...");
}
}


void display()
{
int i;
if(h==0)
printf("\nQUESUE IS EMPTY...");
else
for(i=0;i<10;i++)

printf("%d\n",heap[i]);

}

----------------------------------------------------------------------------------------------

Your's friendly,
[MOHANRAM.G],
ADMIN...