Showing posts with label PROGRAMS-DATA STRUCTURES. Show all posts
Showing posts with label PROGRAMS-DATA STRUCTURES. Show all posts

Friday, October 29, 2010

ARITHMETIC OPERATIONS-WITH & WITHOUT POINTERS



The basic arithmetic operations are addition, subtraction, multiplication and division, although this subject also includes more advanced operations, such as manipulations of percentages, square roots, exponentiation, and logarithmic functions. Arithmetic is performed according to an order of operations. Any set of objects upon which all four arithmetic operations (except division by zero) can be performed, and where these four operations obey the usual laws, is called a field

Addition (+)

Addition is the basic operation of arithemetic. In its simplest form, addition combines two numbers, the addends or terms, into a single number, the sum of the numbers

Subtraction (−)

Subtraction is the opposite of addition. Subtraction finds the difference between two numbers, the minuend minus the subtrahend. If the minuend is larger than the subtrahend, the difference is positive; if the minuend is smaller than the subtrahend, the difference is negative; if they are equal, the difference is zero.

Multiplication (×, ·, or *)

Multiplication is the second basic operation of arithmetic. Multiplication also combines two numbers into a single number, the product. The two original numbers are called the multiplier and the multiplicand, sometimes both simply called factors.

Division (÷ or /)

Division is essentially the opposite of multiplication. Division finds the quotient of two numbers, the dividend divided by the divisor. Any dividend divided by zero is undefined. For positive numbers, if the dividend is larger than the divisor, the quotient is greater than one, otherwise it is less than one (a similar rule applies for negative numbers). The quotient multiplied by the divisor always yields the dividend.


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

A C PROGRAM TO IMPLEMENT ARITHMETIC OPERATIONS-WITH & WITHOUT POINTERS

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 main()
{
int OPT,IN1,IN2,*A,*B,CH;

do
{
printf("\n ARITHMETIC OPERATIONS...");
printf("\n MENU");
printf("\n [1].ADDITION");
printf("\n [2].SUBTRACTION");
printf("\n [3].MULTIPLICATION");
printf("\n [4].DIVISION");
printf("\n OPTION:");
scanf("%d",&OPT);

printf("\n ENTER INPUTS");
printf("\n INPUT 1:");
scanf("%d",&IN1);
printf("\n INPUT 2:");
scanf("%d",&IN2);

switch(OPT)
{

case 1 :

printf("\n ADDITION");
printf("\n COMPUTING WITHOUT POINTERS");
printf("\n SUM:%d",IN1+IN2);
printf("\n COMPUTING WITH POINTERS");
A=&IN1;
B=&IN2;
printf("\n SUM:%d",*A+*B);

break;

case 2 :

printf("\n SUBTRACTION");
printf("\n COMPUTING WITHOUT POINTERS");
printf("\n DIFFERENCE:%d",IN1-IN2);
printf("\n COMPUTING WITH POINTERS");
A=&IN1;
B=&IN2;
printf("\n DIFFERENCE:%d",*A-*B);

break;

case 3 :

printf("\n MULTIPLICATION");
printf("\n COMPUTING WITHOUT POINTERS");
printf("\n PRODUCT:%d",IN1*IN2);
printf("\n COMPUTING WITH POINTERS");
A=&IN1;
B=&IN2;
printf("\n PRODUCT:%d",*A**B);

break;

case 4 :

printf("\n COMPUTING WITHOUT POINTERS");
printf("\n QUOTIENT:%d",IN1/IN2);
printf("\n COMPUTING WITH POINTERS");
A=&IN1;
B=&IN2;
printf("\n QUOTIENT:%d",*A/ *B);
break;

default :
printf("\n INVALID CHOICE");
break;
}

printf("\n DO YOU WISH TO CONTINUE? 1~2:");
printf("\n OPTION:");
scanf("%d",&CH);

}while(CH==1);

printf("\n THANK YOU");
return 0;
}


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

[MOHANRAM.G],
ADMIN...

LIST OPERATIONS-ARRAY IMPLEMENTATION



In computer science, a list or sequence is an abstract data structure that implements an ordered collection of values, where the same value may occur more than once. An instance of a list is a computer representation of the mathematical concept of a finite sequence, that is, a tuple. Each instance of a value in the list is usually called an item, entry, or element of the list; if the same value occurs multiple times, each occurrence is considered a distinct item.

A singly-linked list structure, implementing a list with 3 integer elements.

The name list is also used for several concrete data structures that can be used to implement abstract lists, especially linked lists.

The so-called static list structures allow only inspection and enumeration of the values. A mutable or dynamic list may allow items to be inserted, replaced, or deleted during the list's existence.

Many programming languages provide support for list data types, and have special syntax and semantics for lists and list operations. Often a list can be constructed by writing the items in sequence, separated by commas, semicolons, or spaces, within a pair of delimiters such as parentheses '()', brackets, '[]', braces '{}', or angle brackets '<>'. Some languages may allow list types to be indexed or sliced like array types. In object-oriented programming languages, lists are usually provided as instances of subclasses of a generic "list" class. List data types are often implemented using arrays or linked lists of some sort, but other data structures may be more appropriate for some applications. In some contexts, such as in Lisp programming, the term list may refer specifically to a linked list rather than an array.

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

A C PROGRAM TO IMPLEMENT OPERATIONS IN LIST-ARRAY IMPLEMENTATION

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :5 kb

EXE FILE SIZE :26 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 MAX 10

int a[MAX],TOP=0,NO,NUM,i,A,B,C,V,ELE,POS,n;
int main()
{
int OPT;
char CH;
do
{

printf("\n LIST OPERATION USING LISTS");

printf("\n [1].LIST CREATION");
printf("\n [2].INSERTION-FIRST POSITION");
printf("\n [3].INSERTION-MIDDLE POSITION");
printf("\n [4].INSERTION-LAST POSITION");
printf("\n [5].DELETION -FIRST POSITION");
printf("\n [6].DELETION -MIDDLE POSITION");
printf("\n [7].DELETION -LAST POSITION");
printf("\n [8].ELEMENT SEARCH");
printf("\n [9].ELEMENT MODIFICATON");
printf("\n [10].TRAVERSAL");
printf("\n ENTER CHOICE:");
printf("\n CHOICE:");
scanf("%d",&OPT);

switch(OPT)
{

case 1:
printf("\n LIST CREATION:");
printf("\n CREATE FUNCTION INVOKED...");
CREATE();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 2:
printf("\n ELEMENT INSERTION-FIRST POSITION:");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSF();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 3:
printf("\n ELEMENT INSERTION-MIDDLE POSITION:");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSM();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 4:
printf("\n ELEMENT INSERTION-LAST POSITION::");
printf("\n ELEMENT INSERTION FUNCTION INVOKED...");
INSL();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 5:
printf("\n ELEMENT DELETION-FIRST POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELF();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 6:
printf("\n ELEMENT DELETION-MIDDLE POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELM();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 7:
printf("\n ELEMENT DELETION-LAST POSITION:");
printf("\n ELEMENT DELETION FUNCTION INVOKED...");
DELL();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 8:
printf("\n ELEMENT SEARCH:");
printf("\n SEARCH FUNCTION INVOKED...");
FIND();
break;

case 9:
printf("\n ELEMENT MODIFICATION:");
printf("\n ELEMENT MODIFICATION FUNCTION INVOKED...");
ELEMOD();
printf("\n LIST ELEMENTS AFTER MANIPULATION");
DISPLAY();
break;

case 10:
printf("\n ELEMENT TRAVERSAL:");
printf("\n ELEMENT DISPLAY FUNCTION INVOKED...");
DISPLAY();
default:
printf("\nINVALID CHOICE");

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

//ARRAY CREATION

CREATE()
{
printf("\n ENTER THE TOTAL NUMBER OF ELEMENTS:");
scanf("%d",&NO);
for(i=0;i<=NO;i++)
{
scanf("%d",&NUM);
a[TOP]=NUM;
TOP++;
}
printf("\n CREATION IN PROGRESS...");
}


//INSERTING AN ELEMENT IN THE FIRST POSITION
INSF()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
for(i=TOP;i>=0;i--)
{
a[i]=a[i-1];
}
TOP++;
printf("\n ENTER THE ELEMENT TO BE INSERTED AT THE FIRST POSITION:");
scanf("%d",&a[0]);
}
}

//INSERTING AN ELEMENT IN THE MIDDLE POSITION

INSM()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
printf("\n ENTER THE POSITION TO INSERT THE ELEMENT:");
scanf("%d",&POS);
for(i=TOP;i>=POS;i--)
{
a[i]=a[i-1];
}

TOP++;
printf("\n ENTER THE ELEMENT TO BE INSERTED:");
scanf("%d",&A);
a[i]=A;
}
}

//INSERTING AN ELEMENT AT THE LAST POSITION

INSL()
{
if(TOP>=MAX)
printf("\n THE LIST IS FULL");
else
{
printf("\n INSERTION IN PROGRESS...");
printf("\n ENTER THE ELEMENT TO BE INSERTED:");
scanf("%d",&B);
a[TOP]=B;
TOP++;
}
}

//DELETING AN ELEMENT AT THE FIRST POSITION

DELF()
{
if(TOP==0)
{
printf("\n THE LIST IS EMPTY");
}
else
{
printf("\n DELETION IN PROGRESS...");
n=a[0];
for(i=1;i<=TOP;i++)
{
a[i-1]=a[i];
}
TOP--;
a[TOP]=0;


}
}

//DELETING AN ELEMENT IN THE MIDDLE POSITION

DELM()
{
if(TOP==0)
{
printf("\n THE LIST IS EMPTY");
}
else
{
printf("\n DELETION IN PROGRESS...");
printf("\n ENTER THE POSITION TO DELETE THE ELEMENT:");
scanf("%d",&POS);
n=a[POS];
for(i=POS;i<=TOP;i++)
{
a[i-1]=a[i];
}
TOP--;
a[TOP]=0;
}
}

//DELETING AN ELEMENT AT THE LAST POSITION
DELL()
{
int n;
n=a[TOP];
if(TOP==0)
printf("\n THE LIST IS EMPTY");
else
{
printf("\n DELETION IN PROGRESS...");
a[TOP]=0;
TOP--;
}
}

//ELEMENT SEARCH
FIND()
{
printf("\n ENTER THE ELEMENT TO BE SEARCHED:");
scanf("%d",&ELE);
printf("\n SEARCH IN PROGRESS...");
for(i=0;i{
if(a[i]==ELE)
{
printf("\n THE ELEMENT %d IS FOUND AT %d POSITION:",ELE,i+1);
}

else
{
printf("\n THE ELEMENT %d IS NOT FOUND AT %d POSITION:",ELE,i+1);
}
}
}

//ELEMENT MODIFICATION
ELEMOD()
{
printf("\nENTER THE POSITION OF THE ELEMENT TO BE MODIFIED:");
scanf("%d",&ELE);
B=a[i-1];
if(i<=TOP)
{
printf("\n THE ELEMENT IS:%d",B);
printf("\n ENTER THE NEW ELEMENT:");
scanf("%d",&C);
a[i-1]=C;
printf("\n MODIFICATION IN PROGRESS...");
printf("\n THE ELEMENT %d IS MODIFIED AS %d",B,C);
}
else
{
printf("\n ERROR \n ENTER WITHIN THE DEFINED RANGE");
}
}

// DISPLAY THE ELEMENTS IN THE ARRAY
DISPLAY()
{
for(i=0;i{
printf("\n %d",a[i]);

}
}

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

[MOHANRAM.G],
ADMIN...

SINGLY LINKED LIST



In computer science, a linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence.

Singly-linked-list.svg
A linked list whose nodes contain two fields: an integer value and a link to the next node

Linked lists are among the simplest and most common data structures; they provide an easy implementation for several important abstract data structures, including stacks, queues, associative arrays, and symbolic expressions.

The principal benefit of a linked list over a conventional array is that the order of the linked items may be different from the order that the data items are stored in memory or on disk. For that reason, linked lists allow insertion and removal of nodes at any point in the list, with a constant number of operations.

On the other hand, linked lists by themselves do not allow random access to the data, or any form of efficient indexing. Thus, many basic operations — such as obtaining the last node of the list, or finding a node that contains a given datum, or locating the place where a new node should be inserted — may require scanning most of the list elements.

Linked lists can be implemented in most languages. Languages such as Lisp and Scheme have the data structure built in, along with operations to access the linked list. Procedural languages, such as C, or object-oriented languages, such as C++ and Java, typically rely on mutable references to create linked lists.

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

A C PROGRAM TO IMPLEMENT OPERATIONS IN SINGLY LINKED LIST

COMPILER EMPLOYED: DEV C++ COMPILER-4.9.9.2

SOURCE FILE SIZE :4 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

struct link
{
int item;
struct link *NEXT;
};
typedef struct link NODE;
void INSF();
void INSL();
void INSM();
void DELF();
void DELL();
void DELM();
void DISPLAY();
NODE *HEAD=NULL;
int main()
{
int CH,OPT;

do
{
printf("\n LIST OPERATIONS-SINGLY LINKED LIST-IMPLEMENTATION");
printf("\n MENU:");
printf("\n [1].INSERTION-FIRST POSITION");
printf("\n [2].INSERTION-GIVEN POSITION");
printf("\n [3].INSERTION-LAST POSITION");
printf("\n [4].DELETION-FIRST POSITION");
printf("\n [5].DELETION-GIVEN POSITION");
printf("\n [6].DELETION-LAST POSITION");
printf("\n [7].TRAVERSAL");
printf("\n [8].EXIT");
printf("\n\n ENTER OPTION:");
scanf("%d",&CH);
switch(CH)
{
case 1:
printf("\n INVOKING INSERTION OPERATION...");
INSF();
DISPLAY();
break;
case 2:
printf("\n INVOKING INSERTION OPERATION...");
INSM();
DISPLAY();
break;
case 3:
printf("\n INVOKING INSERTION OPERATION...");
INSL();
DISPLAY();
break;
case 4:
printf("\n INVOKING DELETION OPERATION...");
DELF();
DISPLAY();
break;
case 5:
printf("\n INVOKING DELETION OPERATION...");
DELM();
DISPLAY();
break;
case 6:
printf("\n INVOKING DELETION OPERATION...");
DELL();
DISPLAY();
break;
case 7:
printf("\n INVOKING DISPLAY OPERATION...");
DISPLAY();
break;
case 8:
break;
default:
printf("\n INVALID CHOICE...\n");
break;
}
printf("\n\n DO YOU WISH TO CONTINUE:1~0");
scanf("%d",&OPT);
}while(OPT==1);
printf("\n TERMINATING PROCESS...");

return 0;
}

void INSF()
{
printf("\n\n INSERTION OPERATION INVOKED...");
NODE *TEMP;
TEMP=(NODE *)malloc(sizeof(NODE));
printf("\n ENTER DATA:");
scanf("%d",&TEMP->item);
TEMP->NEXT=HEAD;
HEAD=TEMP;
}

void INSM()
{
printf("\n\n INSERTION OPERATION INVOKED...");
int i=1,pos;
NODE *CUR=HEAD,*TEMP;
printf("\n ENTER POSITION:");
scanf("%d",&pos);
while(pos!=i+1&&CUR!=NULL)
{
CUR=CUR->NEXT;
i++;
}
if(pos==i+1)
{
TEMP=(NODE *)malloc(sizeof(NODE));
printf(" ENTER DATA:");
scanf("%d",&TEMP->item);
TEMP->NEXT=CUR->NEXT;
CUR->NEXT=TEMP;
}
}

void INSL()
{
printf("\n\n INSERTION OPERATION INVOKED...");
NODE *TEMP,*CUR=HEAD;
TEMP=(NODE *)malloc(sizeof(NODE));
printf("\n ENTER DATA");
scanf("%d",&TEMP->item);
while(CUR->NEXT!=NULL)
{
CUR=CUR->NEXT;
}
TEMP->NEXT=CUR->NEXT;
CUR->NEXT=TEMP;
}

void DELF()
{
printf("\n\n DELETION OPERATION INVOKED...");
NODE *TEMP=HEAD;
HEAD=HEAD->NEXT;
printf("DELETED NODE:%d",TEMP->item);
free(TEMP);
}

void DELM()
{
printf("\n\n DELETION OPERATION INVOKED...");
int i=1,pos;
NODE *CUR=HEAD,*TEMP;
printf("ENTER THE POSITION TO BE DELETED:");
scanf("%d",&pos);
while(pos!=i+1&&CUR->NEXT!=NULL)
{
CUR=CUR->NEXT;
i++;
}
if(pos==i+1)
{
TEMP=CUR->NEXT;
CUR->NEXT=TEMP->NEXT;
printf("DELETED ITEM:%d",TEMP->item);
free(TEMP);
}
}

void DELL()
{
printf("\n\n DELETION OPERATION INVOKED...");
NODE *TEMP,*CUR=HEAD;
while(CUR->NEXT->NEXT!=NULL)
{
CUR=CUR->NEXT;
}
TEMP=CUR->NEXT;
CUR->NEXT=NULL;
printf("DELETED ITEM:%d",TEMP->item);
free(TEMP);
}

void DISPLAY()
{
printf("\n\n DISPLAY OPERATION INVOKED...");
NODE *CUR=HEAD;
printf("\n NODES:");
while(CUR!=NULL)
{
printf("\n %d",CUR->item);
CUR=CUR->NEXT;
}
printf("->NULL\n");
}



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

[MOHANRAM.G],
ADMIN...

DOUBLY LINKED LIST


In computer science, a doubly-linked list is a linked data structure that consists of a set of data records, each having two special link fields that contain references to the previous and to the next record in the sequence. It can be viewed as two singly-linked lists formed from the same data items, in two opposite orders.

Doubly-linked-list.svg
A doubly-linked list whose nodes contain three fields: an integer value, the link to the next node, and the link to the previous node.

The two links allow walking along the list in either direction with equal ease. Compared to a singly-linked list, modifying a doubly-linked list usually requires changing more pointers, but is sometimes simpler because there is no need to keep track of the address of the previous node.

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

A C PROGRAM TO IMPLEMENT OPERATIONS IN DOUBLY 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

#define N 100

struct dlinklist
{
struct dlinklist *PREV; /** Stores address of previous node **/
int ELE; /** stores roll number **/

struct dlinklist *NEXT; /** stores address of NEXT node **/
};

/** Redefining dlinklist as node **/
typedef struct dlinklist NODE;

void init(NODE*); /** Input function **/
void ins_aft(NODE*); /** Function inserting before **/
NODE* ins_bef(NODE*); /** Function inserting after **/
NODE* del(NODE*); /** Function deleting a NODE **/

void DISPLAY(NODE*); /** Function for displaying NODE **/
void ELEFIND(NODE*); /** Function for searching NODE **/


int main()
{
NODE *HEAD;
char ch; /* Choice inputing varible */
int OPT; /* Option inputing variable*/
static int FLAG=0; /* Unchanged after iniialization */

HEAD=(NODE*)malloc(sizeof(NODE));
HEAD->NEXT=NULL;
HEAD->PREV=NULL;
do
{
MENU:
printf("\n DOUBLY LINKED LIST OPERATIONS & IMPLEMENTATION");
printf("\n MENU");
printf("\n [1]. NODE INITIALIZATION \n");
printf("\n [2]. INSERTION-BEFORE SPECIFIED NODE\n");
printf("\n [3]. INSERTION-AFTER SPECIFIED NODE \n");
printf("\n [4]. DELETE A PARTICULAR NODE\n");
printf("\n [5]. SEARCH THE NODES\n");
printf("\n [6]. DISPLAY ALL THE NODES\n");
scanf("%d",&OPT);
if(FLAG==0 && OPT!=1)
{
printf("\n WARNING :YOU MUST ATLEAST INITIALIZE ONE NODE...\n");
goto MENU;
}
if(FLAG==1 && OPT==1)
{
printf("\n INITIALIZATION CAN OCCUR ONLY ONCE...\n");
printf("\n NOW YOU CAN INSERT A NODE...\n");
goto MENU;
}
if(OPT==4 && HEAD->NEXT==NULL)
{
printf("\nYOU CANNOT DELETE THE ONLY ONE NODE...\n");
goto MENU;
}
if(FLAG==0 && OPT==1)
FLAG=1;
switch(OPT)
{
case 1:
printf("\n INVOKING INSERTION OPERATION...");
init(HEAD);
break;
case 2:
printf("\n INVOKING INSERTION OPERATION...");
HEAD=ins_bef(HEAD);
break;
case 3:
printf("\n INVOKING INSERTION OPERATION...");
ins_aft(HEAD);
break;
case 4:
printf("\n INVOKING DELETION OPERATION...");
HEAD=del(HEAD);
break;
case 5:
printf("\n INVOKING DEARCH OPERATION...");
ELEFIND(HEAD);
break;
case 6:
printf("\n INVOKING DISPLAY OPERATION...");
DISPLAY(HEAD);
break;
}
printf("\nDO YOU WISH TO CONTINUE [Y~N]:");
ch=getche();
}while(ch=='Y' || ch=='y');

system("pause");
return 0;
}

void init(NODE *CURRENT)
{
printf("\n\n INSERTION OPERATION INVOKED...");
CURRENT->PREV=NULL;
printf("\nENTER THE ELEMENT:\n");
scanf("%d",&CURRENT->ELE);

// fflush(stdin);

CURRENT->NEXT=NULL;
}

void ins_aft(NODE *CURRENT)
{
printf("\n\n INSERTION OPERATION INVOKED...");
int NO; /* inserting a NODE*/
int FLAG=0;
NODE *NEW;
NEW=(NODE*)malloc(sizeof(NODE));
printf("\nENTER THE ELEMENT AFTER WHICH YOU WISH TO INSERT:\n");
scanf("%d",&NO);
init(NEW);
while(CURRENT->NEXT!=NULL)
{
/*** Insertion checking for all nodes except last ***/
if(CURRENT->ELE==NO)
{
NEW->NEXT=CURRENT->NEXT;
CURRENT->NEXT->PREV=NEW;
CURRENT->NEXT=NEW;
NEW->PREV=CURRENT;
FLAG=1;
}
CURRENT=CURRENT->NEXT;
}
if(FLAG==0 && CURRENT->NEXT==NULL && CURRENT->ELE==NO)
{
/*** Insertion checking for last nodes ***/
NEW->NEXT=CURRENT->NEXT;
CURRENT->NEXT=NEW;
FLAG=1;
}
else if(FLAG==0 && CURRENT->NEXT==NULL)
printf("\n MATCH NOT FOUND...\n");
}

NODE* ins_bef(NODE *CURRENT)
{
printf("\n\n INSERTION OPERATION INVOKED...");
int NO; /* inserting a NODE*/
NODE *NEW,*TEMP;
NEW=(NODE*)malloc(sizeof(NODE));
printf("\nENTER THE ELEMENT BEFORE WHICH YOU WANT TO INSERT THE ELEMENT:\n");
scanf("%d",&NO);
init(NEW);
if(CURRENT->ELE==NO)
{
/*** Insertion checking for first NODE ***/
NEW->NEXT=CURRENT;
CURRENT->PREV=NEW;
CURRENT=NEW;
return(CURRENT);
}
TEMP=CURRENT;
while(TEMP->NEXT!=NULL)
{
/*** Insertion checking for all NODE except first ***/
if(TEMP->NEXT->ELE==NO)
{
NEW->NEXT=TEMP->NEXT;
TEMP->NEXT->PREV=NEW;
TEMP->NEXT=NEW;
NEW->PREV=TEMP;
return(CURRENT);
}
TEMP=TEMP->NEXT;
}
/*
If the function does not return from any return statement.
There is no match to insert before the input roll number.
*/
printf("\n MATCH NOT FOUND...\n");
return(CURRENT);
}

NODE* del(NODE *CURRENT)
{
printf("\n\n DELETION OPERATION INVOKED...");
int NO; /* deleting a NODE*/
NODE *NEW,*TEMP;
printf("\nENTER THE ELEMENT TO DELETE:\n");
scanf("%d",&NO);
NEW=CURRENT;
if(CURRENT->ELE==NO)
{
/*** Checking condition for deletion of first NODE ***/
NEW=CURRENT; /* Unnecessary step */
CURRENT=CURRENT->NEXT;
CURRENT->PREV=NULL;
free(NEW);
return(CURRENT);
}
else
{
while(NEW->NEXT->NEXT!=NULL)
{
/*** Checking condition for deletion of ***/
/*** all nodes except first and last NODE ***/
if(CURRENT->NEXT->ELE==NO)
{
NEW=CURRENT;
TEMP=CURRENT->NEXT;
NEW->NEXT=NEW->NEXT->NEXT;
NEW->NEXT->PREV=CURRENT;
free(TEMP);
return(CURRENT);
}
NEW=NEW->NEXT;
}
if(NEW->NEXT->NEXT==NULL && NEW->NEXT->ELE==NO)
{
/*** Checking condition for deletion of last NODE ***/
TEMP=NEW->NEXT;
free(TEMP);
NEW->NEXT=NULL;
return(CURRENT);
}
}
printf("\n MATCH NOT FOUND...\n");
return(CURRENT);
}


void ELEFIND(NODE *CURRENT)
{
printf("\n\n ELEMENT SEARCH OPERATION INVOKED...");
int NO;
printf("\nENTER THE ELEMENT TO SEARCH:\n");
scanf("%d",&NO);
while(CURRENT->NEXT!=NULL)
{
if(CURRENT->ELE==NO)
printf("\n %d",CURRENT->ELE);
CURRENT=CURRENT->NEXT;
}
if(CURRENT->NEXT==NULL && CURRENT->ELE==NO)
printf("\n%d",CURRENT->ELE);
}


void DISPLAY(NODE *CURRENT)
{
printf("\n\n DISPLAY OPERATION INVOKED...\n NODES:");
while(CURRENT!=NULL)
{
printf("\n%d",CURRENT->ELE);
CURRENT=CURRENT->NEXT;
}
}

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

[MOHANRAM.G],
ADMIN...

POLYNOMIAL ADDITION - LINKED LIST APPLICATION



Polynomial arithmetic includes basic mathematical operations such as addition, subtraction, and multiplication. These operations are defined naturally as if the variable x was an element of S. Division is defined similarly, but requires that S be a field. Examples of fields include rational numbers, Zp for p prime, and real numbers. The set of all integers is not a field and does not support polynomial division.

ADDITION

Addition and subtraction are performed by adding or subtracting corresponding coefficients. If

f(x) = \sum_{i=0}^n a_ix^i; g(x) = \sum_{i=0}^m b_ix^i

then addition is defined as

f(x)+g(x)= \sum_{i=0}^m (a_i+b_i)x^i where m > n

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

A C PROGRAM TO IMPLEMENT POLYNOMIAL ADDITION- LINKED LIST 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


//DEFINING A STRUCTURE
struct node
{
signed int COE;
int POWER;
struct node *NEXT;
}*START1,*START2,*ROOT,*SUM,*mul_res;
typedef struct node NODE;


//DISPLAY FUNCTION

void DISPLAY(NODE *CUR)
{
while(CUR!=NULL)
{
printf("%d x %d ",CUR->COE,CUR->POWER);
CUR=CUR->NEXT;
}
}



//READING TWO POLYNOMIAL EQUATIONS -LINKED LIST IMPLEMENTATION

void ins(NODE **ROOT,int c,int p)
{
NODE *TEMP,*CUR;
TEMP=(NODE *)malloc(sizeof(NODE));
CUR=(NODE *)malloc(sizeof(NODE));
CUR=*ROOT;
TEMP->COE=c;
TEMP->POWER=p;
TEMP->NEXT=NULL;
int flag=0;

if(*ROOT==NULL)
{
*ROOT=TEMP;
}

else
{
//FLAG=0 FOR ORDINARY INSERTION

//FLAG=1 FOR MULTIPLICATION

//WITHOUT FLAG, THE RESULT WILL BE 2X2 + 3X2

// AND NOT 5X2(CO-EFF WONT GET ADDED FOR SAME POWER)

while(CUR->NEXT!=NULL && flag==0)

{

if(p==CUR->POWER)
{
CUR->COE=CUR->COE + c;
flag=1;
}
CUR=CUR->NEXT;
}

if(p==CUR->POWER && flag==0) // THIS IS USED FOR MULTIPLICATION
CUR->COE=CUR->COE + c; //ADDITION WONT PASS INTO THIS
else if(flag==0) //CONDITION
CUR->NEXT=TEMP;
}
}



//READING TWO POLYNOMIAL EQUATIONS
void create( )
{
char ch;
int c,p,i;
for(i=1;i<=2;i++)
{
printf("\n ENTER FOR POLYNOMIAL %d (DECREASING POWER ORDER)",i);
printf("\n INSTRUCTION: PRESS C AFTER EACH INPUT TERM \n\n PRESS S AFTER ENTERING EXPRESSION");

ch='c';
// PRESS S AFTER GIVING I/P
while(ch!='s')
{
printf("\nCO-EFFICIENT (space) POWER :");
scanf("%d %d",&c,&p);
if(i==1)
ins(&START1,c,p);

else if(i==2)
ins(&START2,c,p);
scanf("%s",&ch);
}
ROOT=NULL;
}

printf("\n POLYNOMIAL 1:\n");
DISPLAY(START1);

printf("\n POLYNOMIAL 2:\n");
DISPLAY(START2);

}


//POLYNOMIAL ADDITION

void ADD()
{
NODE *CUR1=START1;
NODE *CUR2=START2;
while(CUR1!=NULL && CUR2!=NULL)
{
int k;
if(CUR1->POWER == CUR2->POWER)
{
k=CUR1->COE + CUR2->COE;
ins(&SUM,k,CUR1->POWER);
CUR1=CUR1->NEXT;
CUR2=CUR2->NEXT;
}
else if(CUR1->POWER > CUR2->POWER)
{
ins(&SUM,CUR1->COE,CUR1->POWER);
CUR1=CUR1->NEXT;
}
else if(CUR2->POWER > CUR1->POWER)
{
ins(&SUM,CUR2->COE,CUR2->POWER);
CUR2=CUR2->NEXT;
}
}



// INSERT THE REMAINING ELEMENTS OF CUR2

if(CUR1==NULL)
{
while(CUR2!=NULL)
{
ins(&SUM,CUR2->COE,CUR2->POWER);

CUR2=CUR2->NEXT;
}
}




// INSERT THE REMAINING ELEMENTS OF CUR1
else
while(CUR1!=NULL)
{
ins(&SUM,CUR1->COE,CUR1->POWER);
CUR1=CUR1->NEXT;
}

printf("\n\nTHE SUM:");
DISPLAY(SUM);
}




//MAIN FUNCTION
int main()
{
int CH;
START1=NULL;
START2=NULL;
SUM=NULL;

do
{
printf("\n POLYNOMIAL ADDITION");

printf("\n POLYNOMIAL ADDITION PROCESS INVOKED…");
create();
ADD();
break;

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


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

[MOHANRAM.G],
ADMIN...

STACK -ARRAY 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.

The array implementation aims to create an array where the first element (usually at the zero-offset) is the bottom. That is, array[0] is the first element pushed onto the stack and the last element popped off. The program must keep track of the size, or the length of the stack. The stack itself can therefore be effectively implemented as a two-element structure in C.

The push() operation is used both to initialize the stack, and to store values to it. It is responsible for inserting (copying) the value into the ps->items[] array and for incrementing the element counter (ps->size). In a responsible C implementation, it is also necessary to check whether the array is already full to prevent an overrun.

The pop() operation is responsible for removing a value from the stack, and decrementing the value of ps->size. A responsible C implementation will also need to check that the array is not already empty.

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

A C PROGRAM TO IMPLEMENT OPERATIONS IN STACK -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
void display(void);

int stack[MAXSIZE];
int TOP; //index pointing to the TOP of stack
int main()
{
void PUSH(int);
int POP();
int OPT,CH,i,num;
do

{
printf("\n ARRAY IMPLEMENTATION OF STACK");
printf("\n\n MAIN MENU: ");
printf("\n\n[1].PUSH ELEMENT");
printf("\n[2].POP ELEMENT");
printf("\n[3].TRAVERSAL");
printf("\n\nOPTION:");
scanf("%d",&OPT);

switch(OPT)
{
case 1:
printf("\n\n PUSH OPERATION INVOKED...");
printf("\n ENTER ELEMENT: ");
scanf("%d",&num);
printf("\n\n PUSHING ELEMENT INTO STACK...");
PUSH(num);
break;
case 2:
i=POP();
printf("\n\n POP OPERATION INVOKED...");
printf("\n\n POPPING ELEMENT FROM STACK...");
printf("\n\n ELEMENT POPPED: %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" ,&CH);
}while(CH==1); //END OF DO WHILE
system("pause");
return 0;
} //END OF MAIN


void PUSH(int y)
{

if(TOP>MAXSIZE)
{
printf("\nSTACK FULL");
return;
}
else
{
TOP++;
stack[TOP]=y;
}
}

int POP()
{
int a;
if(TOP<=0)
{
printf("\n STACK EMPTY");
return 0;
}
else
{
a=stack[TOP];
TOP--;
}
return(a);

}

int DISPLAY()
{

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

printf("\n\n TRAVERSING STACK...");
while(i<=TOP)
{
printf("\n ELEMENT %d:%d",j,stack[i++]);
j++;
}
printf("\n");

}

else


printf("\n\nERROR!!! STACK IS EMPTY...");

}


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

[MOHANRAM.G],
ADMIN...

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...