1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nimfa-mama [501]
3 years ago
6

In your own words, describe the structure and function of both the stack and queue data structure and discuss how they are diffe

rent from the perspective of how they are used.
Computers and Technology
1 answer:
Kobotan [32]3 years ago
6 0

Answer:

Following are the answer to this question:

Explanation:

Stack:

The stack data structure is used to create method, parsing, analysis of expression, and tracking. This data type uses the LIFO system, which stands from the Last In First Out. This data structure operates on the top side. In this data structure, it performs two methods, that are "push() and pop()" method and the time complexity of the stack data structure O(1).

Example of Stack:

import java.util.*;//import package

 public class Main //defining class Main

{      

public static void main (String[] ag)//defining main method  

  {

     ArrayDeque<Character> stack = new ArrayDeque<Character>();//creating Character array ArrayDeque  

       stack.push('A'); //add value in stack  

      stack.push('B');//add value in stack  

      stack.push('B'); //add value in stack  

      System.out.println("First Insert:"+stack); //print value         stack.pop();//remove value from stack    

    System.out.println("After removing element: "+stack); //print value         stack.push('B'); //add value in stack    

    stack.pop();//remove value from stack      

 System.out.println("final value: "+stack); //print value    

}

}

Output:

First Insert:[B, B, A]

After removing element: [B, A]

final value: [B, A]

Queue:

The queue data structure is an abstract type, it is similar to the stacks data structure. It is open at both ends when opposed to lines. It follows the FIFO method, which stands for the First-In-First-Out method, At one end data is inserted and at the other end, it deletes the data and the time complexity of the queue data structure O(1).

Example of Queue:

import java.util.*;//import package  

public class Main//defining a class queue

{  

    public static void main(String[] ars)//defining main method

    {  

      LinkedList<Integer> que= new LinkedList<Integer>();//defining integer array LinkedList    

      for (int i = 0; i < 5; i++)//defining fo loop to add value in queue  

     {    

        que.add(i); //use add method to insert value        

}        

System.out.println("Queue value: "+ que); //print queue value      

  int remove= que.remove(); //remove value from the queue          System.out.println("after removing value from queue: "+ remove);//removing element from queue  

      System.out.println(que);  //after removing the element print value  

  }

}  

Output:

Queue value: [0, 1, 2, 3, 4]

after removing value from queue: 0

[1, 2, 3, 4]

You might be interested in
Which of the following statements is true about biometrices as an authentication method
matrenka [14]

Answer:

what are the statements?

Explanation:

7 0
3 years ago
How do you put a fraction into a computer countulater
ad-work [718]

Answer:

i have no clue sorry:(

Explanation:

I didn't do this to get points i promise

3 0
3 years ago
Read 2 more answers
What is the default junk email protection in Outlook 2016?
Shtirlitz [24]
The answer to ur question is D
4 0
3 years ago
Read 2 more answers
What type would the object X be in the following statement:
Y_Kistochka [10]

Answer:

Boolean

Explanation:

If statement condition always returns true or false,which is a boolean data type.

X is true or false

it maybe a variable or an expression.

5 0
3 years ago
Read 2 more answers
CO! Oher...9
kondor19780726 [428]

Answer:

Altitude of the town(h1) = 1,196.8 m

Explanation:

Given:

Height of barometer(h) = 65 cm Hg = 0.65

Standard atmospheric pressure  = 76 cm Hg = 0.76

Density of mercury(Pm) = 13,600 kg/m³

Density of  air (Pa) = 1.25 kg/m³

Find:

Altitude of the town(h1)

Computation:

Pressure due column = Δp mercury column

(Pa)(h1) = (Pm)(h)

(1.25)(h1) = (13,600)(0.76-0.65)

(1.25)(h1) = 1,496

Altitude of the town(h1) = 1,196.8 m

6 0
3 years ago
Other questions:
  • What would I need to make the perfect music video
    10·1 answer
  • Why is the keyboard arranged in the QWERTY style?
    6·2 answers
  • Type the correct answer in the box. In which phishing technique are URLs of the spoofed organization misspelled? _____ is a phis
    11·1 answer
  • In Java; Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or
    10·1 answer
  • A USB device used to transfer photos from the memory card to a hard drive is called a _____.
    12·1 answer
  • Hide Time Remaining A
    11·1 answer
  • Type the correct answer in the box. Spell the word correctly.
    15·2 answers
  • Explain the Decision making statement​
    15·1 answer
  • 7.4 Lesson Practice (projectstem): what is output if the user is enters 2?​
    8·1 answer
  • In Super Mario Bros., you become Mario and your friend is Mario’s younger brother Luigi. Your job is to race through Mushroom Ki
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!