C language, 2 stacks in the two stack implementation queue, what does it mean? Two linked lists? Or

Updated on technology 2024-02-27
9 answers
  1. Anonymous users2024-02-06

    The original meaning of the question is to implement the function of one queue with two stacks.

    Description of the data structure: Stack: FIFO Queue: FIFO FIFO Implementation Method 1, specific: Team Column: Stack A into Stack;

    For example, from the top of the stack to the bottom of the stack, the order is: d c b a; Queue delisting: Check whether the number of stack elements is 1, if so, it will pop up;

    If it is false, all elements of stack A are out of the stack pop and pressed into stack B; Stack B, Stack Top Element, Pop; All elements of stack b are pressed into stack a.

    For example: stack A bullet stack, stack B presses stack, stack B from the top of the stack to the bottom of the stack in order: a b c d; Bounce the top element A of the stack and press the remaining elements back into the stack A; Stack A from the top of the stack to the bottom of the stack is: b c d;

    Implementation method two, specific:

    Team Column: Determine whether the number of stack elements is 1, if so, pop up;

    If it is false, all elements of stack A are out of the stack pop and pressed into stack B; Press the new element into stack A; All elements of stack b are pressed into stack a.

    Queue out: stack A out of stack;;

    Summary: Queue in and out of the queue are implemented.

    Implement the functionality of one stack with two queues.

    Implementation method 1, specific:

    Stack: All elements are placed in queue A;

    For example, the order from the end of the queue to the head of the queue is as follows: d c b a; Out of the stack: Check whether the number of stack elements is 1, if it is true, queue A will be listed;

    If false, all elements of queue a are out of the queue and into queue b, and the last element is not in queue b, and the element is output; All elements of queue b are placed in queue a;

    For example, d c b a is taken out of the queue, d is output, c b a is added to queue b, and finally returned to queue a. Last-in, first-out is realized.

    Implementation method 2, specific: Stacking: Similar to method 1 out of the stack Stacking: Similar to method 1 entering the stack.

    Summary: Implemented stack entry and stack exit operations.

  2. Anonymous users2024-02-05

    I'm guessing it's the queue feature implemented with the stack. It is to give you two stacks, how to achieve the effect of the queue, first-in, first-out.

    Now that the stack has been given to you. You just need to use 2 stacks and pour them around. It's relatively easy to implement.

    Just use the stack method push and pop for all.

    Queues and stacks are two parallel concepts, and I haven't heard of stacks in queues. But I'm talking about one of the most common stack and queue problems.

  3. Anonymous users2024-02-04

    Can you make the problem clearer?

  4. Anonymous users2024-02-03

    Both stacks and queues can be implemented with arrays, and they can also be implemented with linked lists! Broadly speaking, stacks are also queues! Both of these are ordinal table structures!

    The stack is also called the first-in-first-out queue, which can also be called the last-in, first-out queue, and the queue is also called the first-in, first-out queue! These two are collectively referred to as single-in, single-out queues!

    Stacks are single-ended queues! The queue is a single-in, single-out double-ended queue!

    There is also a double-in, double-out double-ended queue! All three types of queues are linear tables! This can be done with arrays or linked lists!

    In addition to the commonly used dynamic linked lists, it can also be implemented with static linked lists! Static linked lists are implemented with arrays and cursors (an integer used in place of pointers)!

    PS: stack (lifo or filo), queue (fifo), double in and double out queue (deque);

    It is the three forms of queues, and the stack is a single-ended queue, first in and last out! Queue single-in, single-out double-ended queue FIFO, dual-queue DEQUE is a double-in double-out double-ended queue! It's a stack and a queue relationship!

    All are linear tables (sequential tables).

    Linear tables (sequential lists) can be implemented in three ways: arrays, linked lists (dynamic linked lists), and static linked lists! It's their relationship to arrays!

  5. Anonymous users2024-02-02

    A stack, also known as a stack, is an arithmetic-constrained linear table. The restriction is that inserts and deletes are allowed only on one end of the table. This end is called the top of the stack, and conversely, the other end is called the bottom of the stack.

    Inserting a new element into a stack is also known as entering the stack, entering the stack or pressing the stack, which is to put the new element on top of the stack element to make it a new top element; Deleting an element from a stack, also known as stacking or destacking, is the process of removing the top element of the stack so that its neighbors become the new top element.

    A queue is a special kind of linear table, which is unique in that it only allows deletion operations at the front end of the table and insert operations at the back end of the table (rear). The end where the insert operation takes place is called the tail of the queue, and the end where the delete operation takes place is called the head of the line.

    Both are endpoint operations, the queue is FIFO (first in first out), the stack is lifo (last in first out), there are two queues for pointers, and the stack has only one top pointer.

    The above is from the perspective of data structures, from the perspective of the operating system, all data structures are operations on virtual memory, heaps are heaps, stacks are stacks, stacks refer to the virtual memory space used by C language functions, and heaps have the operating system heap manager to manage the part of virtual memory, from the perspective of C language, the memory dynamically allocated by the malloc function is heap memory.

  6. Anonymous users2024-02-01

    Both are endpoint operations, the queue is FIFO (first in first out), the stack is lifo (last in first out), there are two queues for pointers, and the stack has only one top pointer.

  7. Anonymous users2024-01-31

    Only elements are allowed to be inserted and deleted at endpoints.

  8. Anonymous users2024-01-30

    What are you talking about? Are you talking about storage structures?

    To put it simply, it is:

    Elements of a stack can only enter and exit from the tail of the queue, while elements of the queue can enter and exit from the end of the queue.

  9. Anonymous users2024-01-29

    A queue is a sequential table, first-in, first-out.

    As a data structure, the stack can only be deleted or inserted in one segment, so it is first-in, last-out.

    I haven't heard much of the concept of queue stacks, and the difference between a linked list stack, also known as a chain stack, and a normal sequential stack is "head plug deletion". The chain stack is implemented in the form of a single linked list, each time you insert and delete at the end of the linked list, you have to traverse the entire linked list to find the tail node, and when you delete and insert in the head of the linked list, you only need to follow the head pointer to find the first element node of the linked list.

    The queue stack should be implemented in the form of a queue.

    The queue is first-in, first-out, and the table is deleted at the front and inserted at the end.

Related questions
19 answers2024-02-27

Write in the click of button1; Then write using system in the main function; >>>More

4 answers2024-02-27

for(i=3;i<=ihuffsize[n-1];i++)uint_8s[0]=0;

uint_8s[1]=uint_8[p]; >>>More

6 answers2024-02-27

This little poem is concise and full of meaning, and the writing style is very distinctive. The poet skillfully handles the relationship between narrative and lyricism. The first three sentences of the narrative describe the environment, using layers of in-depth and repeated rendering techniques to create an atmosphere, pave the way for the fourth lyricism, highlight the status of the lyrical sentence, and make the lyrical sentence appear particularly vigilant and powerful. >>>More

8 answers2024-02-27

I only know Chapter 35 You can't judge people by their appearance

31 answers2024-02-27

The full moon is difficult to round.

People are awake and not awake. >>>More