answersLogoWhite

0

#include <stdio.h>

#define FALSE 0

#define NULL 0

typedef struct {

int dataitem;

struct listelement *link;

} listelement;

void Menu (int *choice);

listelement * AddItem (listelement * listpointer, int data);

listelement * RemoveItem (listelement * listpointer);

void PrintQueue (listelement * listpointer);

void ClearQueue (listelement * listpointer);

main () {

listelement listmember, *listpointer;

int data,

choice;

listpointer = NULL;

do {

Menu (&choice);

switch (choice) {

case 1:

printf ("Enter data item value to add ");

scanf ("%d", &data);

listpointer = AddItem (listpointer, data);

break;

case 2:

if (listpointer NULL)

printf ("queue is empty!\n");

else

while (listpointer != NULL) {

printf ("%d\t", listpointer -> dataitem);

listpointer = listpointer -> link;

}

printf ("\n");

}

void ClearQueue (listelement * listpointer) {

while (listpointer != NULL) {

listpointer = RemoveItem (listpointer);

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue&lt;Item&gt; reverse (Queue&lt;Item&gt; queue) { Stack&lt;Item&gt; stack; Item item; while (queue.remove(&amp;item)) { stack.push(item); } while(stack.pop(&amp;item)) { queue.add(item); } return queue; }


Data structure algorithms using C?

array,linklist,queue,stack,tree,graph etc...


Why does LIFO order follows in stack and why does FIFO order follows in queue?

LIFO and stack are synonyms, so are FIFO and queue.


Can the program counter be eliminated by using the top of the stack as a program count?

No. The program counter must be stored in a dedicated register. The stack is in working memory and you cannot operate on working memory; all values must be moved into a register in order to operate upon them. It makes no sense to move a program counter in and out of memory unless performing a context switch and you can't use a stack for context switching; a priority queue must be used for this. Keep in mind that the address of the top of the stack has to be moved in and out of its register during a context switch. It doesn't make sense to load the stack register from a priority queue before you can determine where the program counter value is. It's easier to keep all state information in the same place in the priority queue where it belongs.


Stack c language program of palindrome?

what ever you assume

Related Questions

Write a program to convert stack into queue using c language?

In order to write a program to convert stack into queue using c language you must be able to identify the proper program. Having a special certification in programing will be beneficial as well to make sure you recognize the proper queues for the programs.


Write a program in c language to reverse elements of a queue?

There are many ways to reverse the order of the elements in a queue. Provided that you have access to the implementation of the queue, it is of course easy to read the elements from the tail end rather than the front end, thus reversing the elements. However, considering the queue as a black box, and assuming the queue only allows for its characteristic operations (removal of head element, addition to tail), the best method to reverse the elements in a queue to engage a stack. You'd remove the elements from the queue (always reading the head of the queue), and push each element onto the stack. When the queue is empty, you reverse that process: pop each element from the stack until it is empty, and add each element in this order to the end of the queue. Your queue will have the exact same elements as in the beginning, but in reverse order. The exact implementation of this in C, or in any other programming language, is trivial, but the exact source code depends on the implementation of queue and stack containers. Following is pseudocode: Queue&lt;Item&gt; reverse (Queue&lt;Item&gt; queue) { Stack&lt;Item&gt; stack; Item item; while (queue.remove(&amp;item)) { stack.push(item); } while(stack.pop(&amp;item)) { queue.add(item); } return queue; }


Data structure algorithms using C?

array,linklist,queue,stack,tree,graph etc...


Why does LIFO order follows in stack and why does FIFO order follows in queue?

LIFO and stack are synonyms, so are FIFO and queue.


Can the program counter be eliminated by using the top of the stack as a program count?

No. The program counter must be stored in a dedicated register. The stack is in working memory and you cannot operate on working memory; all values must be moved into a register in order to operate upon them. It makes no sense to move a program counter in and out of memory unless performing a context switch and you can't use a stack for context switching; a priority queue must be used for this. Keep in mind that the address of the top of the stack has to be moved in and out of its register during a context switch. It doesn't make sense to load the stack register from a priority queue before you can determine where the program counter value is. It's easier to keep all state information in the same place in the priority queue where it belongs.


What is difference between stack snd queue?

In stack , the object which is last in will be first out (LIFO), whereas in queue the object which is first in will be first out (FIFO).


Stack c language program of palindrome?

what ever you assume


How to write aC program to merge two singly linked list?

write a c program to circular queue


Is cursor implementation possible in queue or stack?

yes,cursor implementation possible in priority queue.


Array implementation of priority queue example program in c plus plus?

yes


Write a c program to perform stack operation?

int top=-1; int stack[10];


Double ended stack?

Double ended queue