hi please help me....can you give me a code for queue program???
the flow look like this:
KEY FUNCTION
E Enqueue
D Dequeue
H Hide implementation
S Show implementation
R Bubble sort

*note 10 numbers to be inputed.

> hi please help me....can you give me a code for queue program???

Lol. Very funny.

I can give you the pseudcode ^,...,^. You'd better implement...

Enqueue:

1 if (queue full)
1 return false
2 allocate (newPtr)
3 newPtr -> data = data
4 newPtr -> next = null
5 if (queue.count = 0)
Insert into null queue
1 queue.front = newPtr
6 else
Insert into queue with data
1 queue.rear -> next = newPtr
7 queue.rear = newPtr
8 queue.count = queue.count + 1
9 return true
End enqueue

Dequeue:

if (queue empty)
1 return false
2 dataOut = queue.front -> data
3 dltPtr = queue.front
4 if (queue.count = 1)
Delete data in queue with
only one item
1 queue.rear = null
5 queue.front = queue.front -> next
6 queue.count = queue.count - 1
7 recycle (dltPtr)
8 return true
End dequeue

>can you give me a code for queue program???
I can do one better. I'll give you code for a queue and a stack program:

#ifndef JDEQUE_H
#define JDEQUE_H

/* Increment or decrement an index with wraparound */
#define _wrap_decr(i,n)      ( (i) = ( (i) == 0 ? n - 1 : (i) - 1 ) )
#define _wrap_incr(i,n)      ( (i) = ( (i) == n - 1 ? 0 : (i) + 1 ) )

#define _deque_ready(d)      ( (d)._base != 0 )

#define _deque_full(d)       ( (d)._fill == (d)._size )
#define _deque_empty(d)      ( (d)._fill == 0 )

/* Generic push and pop. Calling code defines the index and update logic */
#define _deque_push(d,x,i,f) ( ++(d)._fill, (d)._base[(i)] = (x), f ( (i), (d)._size ) )
#define _deque_pop(d,i,f)    ( --(d)._fill, (d)._base[f ( (i), (d)._size )] )

/* Concrete push/pop front and push/pop back */
#define _deque_pushf(d,x)    ( _deque_push ( (d), (x), (d)._front, _wrap_decr ) )
#define _deque_pushb(d,x)    ( _deque_push ( (d), (x), (d)._back, _wrap_incr ) )
#define _deque_popf(d)       ( _deque_pop ( (d), (d)._front, _wrap_incr ) )
#define _deque_popb(d)       ( _deque_pop ( (d), (d)._back, _wrap_decr ) )

#define _deque_init(d,buf,n) do { \
  (d)._base = (buf);              \
  (d)._size = (n);                \
  (d)._fill = 0;                  \
  (d)._front = 0;                 \
  (d)._back = 1;                  \
} while ( 0 )

struct _deque {
  char     *_base;
  unsigned  _size;
  unsigned  _fill;
  unsigned  _front;
  unsigned  _back;
};

#endif

Of course, you'll have to figure out how to use it. :D

heres my code.
i cant make a declaration for the keys for enqueue, dequeue,hide implementation, show implementation and sorting...

here:

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

#define MAX 10

void addq ( int *, int, int *, int * ) ;
int delq ( int *, int *, int * ) ;

void main( )
{
int arr[MAX] ;
int front = -1, rear = -1, i ;

clrscr( ) ;

addq ( arr, 23, &front, &rear ) ;
addq ( arr, 9, &front, &rear ) ;
addq ( arr, 11, &front, &rear ) ;
addq ( arr, -10, &front, &rear ) ;
addq ( arr, 25, &front, &rear ) ;
addq ( arr, 16, &front, &rear ) ;
addq ( arr, 17, &front, &rear ) ;
addq ( arr, 22, &front, &rear ) ;
addq ( arr, 19, &front, &rear ) ;
addq ( arr, 30, &front, &rear ) ;
addq ( arr, 32, &front, &rear ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

i = delq ( arr, &front, &rear ) ;
printf ( "\nItem deleted: %d", i ) ;

getch( ) ;
}

/* adds an element to the queue */
void addq ( int *arr, int item, int *pfront, int *prear )
{
if ( *prear == MAX - 1 )
{
printf ( "\nQueue is full." ) ;
return ;
}

( *prear )++ ;
arr[*prear] = item ;

if ( *pfront == -1 )
*pfront = 0 ;
}

/* removes an element from the queue */
int delq ( int *arr, int *pfront, int *prear )
{
int data ;

if ( *pfront == -1 )
{
printf ( "\nQueue is Empty." ) ;
return NULL ;
}

data = arr[*pfront] ;
arr[*pfront] = 0 ;
if ( *pfront == *prear )
*pfront = *prear = -1 ;
else
( *pfront )++ ;

return data ;
}

program to write an object and read an object from file in cpp
program to copy contents of one file to another file in cpp
program to concatenate two files in cpp.

Edited 6 Years Ago by polisure: n/a

This article has been dead for over six months. Start a new discussion instead.