Insertion sort ...... Selection sort...... Bubble sort...... Recursive...... Doubly linked list...... Sort more then to Least By Linked List...... Average By Linked list...... Singly Linked List...... Circular Queue...... Perfectly Queue...... Evaluate by Stack...... postfix to infix...... infix To postfix...... stack And queue

Oracle and Java Blog

Mobile Embedded Features

java.net Forums: Message List - Java Web Services and XML

java.net's Javapedia web

Showing posts with label queue. Show all posts
Showing posts with label queue. Show all posts

Wednesday, May 9, 2007

Circular Queue

#include

#define MAXQUEUE 5

typedef struct {
char data[MAXQUEUE];
int rear;
int front;
int counter;
}QUEUE;

void initial(QUEUE *q);
int enqueue(QUEUE *q,char item);
int dequeue(QUEUE *q,char *ret);

void initial(QUEUE *q){

q->front=-1;
q->rear=-1;
q->counter=0;

}

int enqueue(QUEUE *q,char item)
{
if (q->counter == MAXQUEUE){
printf("FULL QUEUE !!! \n");
return 0;
}
else
{
q->counter++;
q->rear=(q->rear+1)%MAXQUEUE;
q->data[q->rear] = item;
printf("\t enqueue <- %c \n",q->data[q->rear]);

}
return 1;
}

Perfectly Queue

#include

#define MAXQUEUE 5

typedef struct {
char data[MAXQUEUE];
int rear;
int front;
}QUEUE;

void initial(QUEUE *q);
int enqueue(QUEUE *q,char item);
int dequeue(QUEUE *q,char *ret);

void initial(QUEUE *q){

q->front=-1;
q->rear=-1;

}

int enqueue(QUEUE *q,char item)
{
if (q->rear == MAXQUEUE){
printf("FULL QUEUE !!! \n");
return 0;
}
else
{
q->rear++;
q->data[q->rear] = item;
printf("\n\t enqueue <- %c",q->data[q->rear]);

}
return 1;
}
} int dequeue(QUEUE *q,char *ret)
{
if (q->front== q->rear)
{
printf("Empty QUEUE !!! \n");
return 0;
}
else
{
q->front++;
*ret = q->data[q->front];
}
return 1;
}

void main(){

QUEUE q;
char *element="ABCDE";
char r;
int i=0;

initial(&q);

// enqueue
printf("ENQUEUE \n");

while(enqueue(&q,element[i]))
i++;

// dequeue
printf("\n DEQUEUE \n");
while(dequeue(&q,&r))
{
printf("\n\t dequeue ->%c",r);
}
}

stack And queue

#include

#define MAXSTACK 5

typedef struct
{
int sp;
int Data[MAXSTACK];
}STACK;


void Initialize(STACK *s);
int push(STACK *s,int item);
int pop(STACK *s,int *ret);
int full(STACK *s);
int empty(STACK *s);

void Initialize(STACK *s)
{
s->sp=0;
}

int push(STACK *s,int item)
{
if(full(s))
{
printf("Stack is full !!!\n");
return 0;
}
else
{
printf("\tpush -> %d\n",item);
s->Data[s->sp++]=item;
}
return 1;
}
int full(STACK *s)
{
if(s->sp==MAXSTACK)
return 1;
return 0;
}

...................................................

#include

#define MAXSTACK 5

typedef struct
{
int sp;
int Data[MAXSTACK];
}STACK;


void Initialize(STACK *s);
int push(STACK *s,int item);
int pop(STACK *s,int *ret);
int full(STACK *s);
int empty(STACK *s);

void Initialize(STACK *s)
{
s->sp=0;
}

int push(STACK *s,int item)
{
if(full(s))
{
printf("Stack is full !!!\n");
return 0;
}
else
{
printf("\tpush -> %d\n",item);
s->Data[s->sp++]=item;
}
return 1;
}
int full(STACK *s)
{
if(s->sp==MAXSTACK)
return 1;
return 0;
}
................................................