| | |
queue program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
•
•
hi please help me....can you give me a code for queue program???
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
I can give you the pseudcode ^,...,^. You'd better implement...
Enqueue:
Dequeue:
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
•
•
•
•
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
Say It Like It Is.
Có sao nói vậy.
Có sao nói vậy.
>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:
Of course, you'll have to figure out how to use it.
I can do one better. I'll give you code for a queue and a stack program:
C++ Syntax (Toggle Plain Text)
#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
I'm here to prove you wrong.
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
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 ;
}
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 ;
}
![]() |
Similar Threads
- printing elements in a queue (C++)
- HELP-search extender, shopping assistant, search assistant (Viruses, Spyware and other Nasties)
- queue program question (C++)
- rundll32.exe problems (Windows NT / 2000 / XP)
- bridge.dll run error HJT log inside (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Winsock
- Next Thread: Compilation process
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






