NEWS: Total Picture Views: 147066 | Total Article Views: 155668 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. How to read a JSON and work with it | 3. PickUpThings with Becker Robot | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Queue Array C

Description:

In this exampe I will be showing you to use a queue.

Code:

// this programs read an ineger and store its digits into a queue 
// then prints the digits in reverse order
#include <stdio.h>
// define a symbolic constant to hold the capacity of the queue
#define MaxQ 10

#include <queue.h>

main(){
	int n;

	// create an empty queue 
	Queue Q=initQueue();
	printf("Enter a positive integer:");
	scanf("%d",&n);

	// parse n into digits and store these digits into a queue
	while(n>0){
		enqueue(Q,n%10); // insert a digit of n
		n=n/10;
	}

	// prints the digits from the queue in reverse order
	printf("\nDigits in reverse order:");
	while(!empty(Q))
		printf("%d", dequeue(Q));
	printf("\n"); 
}
Attachments: None

Tags: Queue

Total Views: 736

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/27/15 and updated on 02/27/15


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.