answersLogoWhite

0


Best Answer

//Library File

#include

//Class to hold a person's data

class person

{

public:

int arr_time,trans_time;

};

//Class to implement queue

class Queue

{

private:

person data[5]; // An array object of the person class

int front,back; // 'front' and 'back' variables to point to the front value and back value

int count; //'count' counts the no. of elements present in the queue

public:

Queue() //Constructor

{

front=back=0;

count=0;

}

void inqueue(int a_tym,int t_tym) // Function to add data into the queue

{

if(count>=5)

cout<<"\n The queue is full.";

else

{

data[back].arr_time=a_tym;

data[back].trans_time=t_tym;

if(count<5&&count>0&&back!=4)

back++;

else if(count<5&&count>0&&back==4)

back=0;

count++;

}

}

void dequeue() // Function to remove data from the queue

{

if(count<=0)

cout<<"\n The queue is empty.";

else

{

if(count<5&&count>0&&front==4)

front=0;

else if (count<5&&count>0&&back!=4)

front++;

count--;

}

}

void Front() // Function to show the first element on the queue

{

cout<<"\n The arrival time of the first customer is :"<

cout<<"\n The transaction time is :"<

}

void Empty() // Function to check if the queue is empty or full

{

if(count<=0)

cout<<"\n The queue is empty.";

else if(count>=4)

cout<<"\n The queue is full.";

else

cout<<"\n The queue is not empty.";

}

};

void main()

{

Queue q1;

q1.inqueue(33,4);

q1.Front();

q1.inqueue(34,6);

q1.Front();

q1.dequeue();

q1.Front();

q1.inqueue(34,1);

q1.inqueue(35,3);

q1.inqueue(36,5);

q1.inqueue(39,7);

q1.Empty();

q1.Front();

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

There is no such thing as 'circular array'.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What problem is overcome by using a circular array for a static queue?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is static array and dynamic array in visual basic?

Generally speaking, a static array is a fixed-length array while a dynamic array is a variable-length array. However, we prefer the terms fixed-length and variable-length because static objects are objects that are allocated in static memory at compile time, which means they have a fixed offset address (the offset remains the same for each execution and will not change at runtime). Dynamic objects, on the other hand, are allocated and destroyed at runtime, which means they have dynamic addresses; each time the object is instantiated we cannot guarantee it resides at the same address. To put it another way, all static arrays must be fixed-length arrays, but not all fixed-length arrays must be static arrays. We can allocate a fixed-length array in static memory (in which case it is also a static array), but we can also allocate a fixed-length array on the call stack or on the heap, in which case we can potentially create more than one instance of that array, each with its own unique address. Consider a recursive function that instantiates a local (non-static) fixed-length array: each instance of that function would instantiate a new instance of that array, each with its own unique address. Similarly with multi-threaded applications: each thread has its own call stack, thus we could potentially have multiple threads invoking the same function and thus instantiating multiple instances of the same array in different call stacks, each with its own unique address. And if we allocate a fixed-length array on the heap, we have no guarantee where that array will be allocated. So whenever we speak of static or dynamic allocations, remember that we are specifically referring to the address (or at least the offset address). Dynamic addresses can change at runtime, static addresses cannot. Although the physical address of a static object can change between executions, its offset address (relative to the start of the static data segment) can never change -- not without recompiling the executable.


What is the limitation of linear queue and how do you overcome using circular queue?

in linear queue when any element is pop out than we do size-1 value changing ie like in the pile of coin when we take out the last coin then all changes there places so likewise we have to change the position of each element..... we can overcome by circular one as we have to change the value of the first and last not the values changes in the array.... but circular queue also had limitation that either u have to use it as size-1 queue or it will show you full even though it is empty fully....as first==last...


What is the difference between a fixed size array and a variable size array?

The obvious answer is that one has a constant size while the other does not. More specifically, a fixed-size array is one where the size is known at compile time and does not change at runtime. By contrast, the size of a variable-sized array may or may not be known at compile time but may change at runtime. We often refer to a variable-size array as being a dynamic array, however some people (myself included) incorrectly refer to a fixed-size array as being a static array. The misunderstanding largely comes from the fact that we often refer to the heap (or free store) as being dynamic memory because all dynamic variables are allocated there (including variable-size arrays). But the term dynamic array does not refer to the memory, it refers to the dynamic -- as in changeable -- nature of the array itself. By contrast, a fixed-size array is only deemed static if it is statically allocated, in which case it will be allocated in the program's data segment along with all other static variables, global variables and constants. But a local fixed-size array is allocated on the program's stack and is therefore, by definition, non-static. Moreover, you can allocate a fixed-size array on the heap!


When an array is declared does c automatically initializes its elements to zero?

For global/static variables: yes.For auto variables: no.


When you pass an array element to a method the method receives?

Yes, you can use array-elements as parameters. Do you have any problem with that?

Related questions

What is the difference between queues and circular queues?

A queue can use a dynamic array, or a linked list, but if using static memory, the queue becomes a circular queue because the underlaying data structure is a static circular array. This means the ends of the array are attached.


Can array be initialized if they are static?

Yes.


What static array and dynamic array in visual basic?

Generally speaking, a static array is a fixed-length array while a dynamic array is a variable-length array. However, we prefer the terms fixed-length and variable-length because static objects are objects that are allocated in static memory at compile time, which means they have a fixed offset address (the offset remains the same for each execution and will not change at runtime). Dynamic objects, on the other hand, are allocated and destroyed at runtime, which means they have dynamic addresses; each time the object is instantiated we cannot guarantee it resides at the same address. To put it another way, all static arrays must be fixed-length arrays, but not all fixed-length arrays must be static arrays. We can allocate a fixed-length array in static memory (in which case it is also a static array), but we can also allocate a fixed-length array on the call stack or on the heap, in which case we can potentially create more than one instance of that array, each with its own unique address. Consider a recursive function that instantiates a local (non-static) fixed-length array: each instance of that function would instantiate a new instance of that array, each with its own unique address. Similarly with multi-threaded applications: each thread has its own call stack, thus we could potentially have multiple threads invoking the same function and thus instantiating multiple instances of the same array in different call stacks, each with its own unique address. And if we allocate a fixed-length array on the heap, we have no guarantee where that array will be allocated. So whenever we speak of static or dynamic allocations, remember that we are specifically referring to the address (or at least the offset address). Dynamic addresses can change at runtime, static addresses cannot. Although the physical address of a static object can change between executions, its offset address (relative to the start of the static data segment) can never change -- not without recompiling the executable.


What is static array and dynamic array in visual basic?

Generally speaking, a static array is a fixed-length array while a dynamic array is a variable-length array. However, we prefer the terms fixed-length and variable-length because static objects are objects that are allocated in static memory at compile time, which means they have a fixed offset address (the offset remains the same for each execution and will not change at runtime). Dynamic objects, on the other hand, are allocated and destroyed at runtime, which means they have dynamic addresses; each time the object is instantiated we cannot guarantee it resides at the same address. To put it another way, all static arrays must be fixed-length arrays, but not all fixed-length arrays must be static arrays. We can allocate a fixed-length array in static memory (in which case it is also a static array), but we can also allocate a fixed-length array on the call stack or on the heap, in which case we can potentially create more than one instance of that array, each with its own unique address. Consider a recursive function that instantiates a local (non-static) fixed-length array: each instance of that function would instantiate a new instance of that array, each with its own unique address. Similarly with multi-threaded applications: each thread has its own call stack, thus we could potentially have multiple threads invoking the same function and thus instantiating multiple instances of the same array in different call stacks, each with its own unique address. And if we allocate a fixed-length array on the heap, we have no guarantee where that array will be allocated. So whenever we speak of static or dynamic allocations, remember that we are specifically referring to the address (or at least the offset address). Dynamic addresses can change at runtime, static addresses cannot. Although the physical address of a static object can change between executions, its offset address (relative to the start of the static data segment) can never change -- not without recompiling the executable.


Which queue most efficient queue using array?

circular queue


Write a c program to reverse an array without using another array?

public static int[] reverseArray(int[] array) { int i = 0, j = array.length - 1; for (i = 0; i &lt; array.length / 2; i++, j--) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; }


How can an array help you solve a related multiplication and division problem?

? problem division and multiplication related a solve you help array an can how


What is the limitation of linear queue and how do you overcome using circular queue?

in linear queue when any element is pop out than we do size-1 value changing ie like in the pile of coin when we take out the last coin then all changes there places so likewise we have to change the position of each element..... we can overcome by circular one as we have to change the value of the first and last not the values changes in the array.... but circular queue also had limitation that either u have to use it as size-1 queue or it will show you full even though it is empty fully....as first==last...


How do you draw an array to solve a problem?

The answer will depend on what the problem is: some can be solved using an array but for others, arrays are a complete waste of time.


What is the default value of the array elements in an integer array?

'0' Try this: public static void main(String[] args){ } The output would be 0 even though you did not initialize any value in the int array.


What is array in structures?

array is used to store the ame datatypes syntex: int array[]=new int[size]; dynamic declaration of array insertion array[1]=20; 2nd way: int array[]={10,20,30}; *important:- int array[20]={20,30,49,....} this way is wrong in java as this is static way and in java all is done dynamically


Write a program to sort elements of an array in ascending order?

import java.util.Arrays; public class arraysort { public static void main(String[] a) { int array[] = { 2, 5, -2, 6, -3 }; Arrays.sort(array); for (int i : array) { System.out.println(i); } } }