Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QT C++ DATA Structures
Forum Updated to NodeBB v4.3 + New Features

QT C++ DATA Structures

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 3 Posters 863 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ELIF
    wrote on 4 Aug 2022, 14:11 last edited by
    #1

    How to access any element of stack or queue without pop() operation in c++ ?

    J 1 Reply Last reply 4 Aug 2022, 14:26
    0
    • E ELIF
      5 Aug 2022, 05:39

      @JonB yes , ofcourse.

      J Offline
      J Offline
      JonB
      wrote on 5 Aug 2022, 05:54 last edited by JonB 8 May 2022, 06:55
      #7

      @ELIF
      Then why not say so from the start?! So your question is not connected to Qt C++ data strictures structures after all. You can see the methods of std::queue from the docs:

      The std::queue class is a container adaptor that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure.

      The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.

      Accessors are front() and back() It's a queue. So you cannot access middling elements, and why would you want to if you are choosing to use a queue?

      However, @JoeCFD's std::dequeue does allow access to middling elements. See Access c++ queue elements like an array for a discussion.

      1 Reply Last reply
      2
      • E ELIF
        4 Aug 2022, 14:11

        How to access any element of stack or queue without pop() operation in c++ ?

        J Offline
        J Offline
        JonB
        wrote on 4 Aug 2022, 14:26 last edited by
        #2

        @ELIF
        Depends what library you are using for "stack" or "queue".

        1 Reply Last reply
        0
        • E Offline
          E Offline
          ELIF
          wrote on 4 Aug 2022, 14:28 last edited by
          #3

          I will use queue.

          J 1 Reply Last reply 4 Aug 2022, 15:39
          0
          • J Offline
            J Offline
            JoeCFD
            wrote on 4 Aug 2022, 14:48 last edited by
            #4

            std::deque may be a better option.

            1 Reply Last reply
            1
            • E ELIF
              4 Aug 2022, 14:28

              I will use queue.

              J Offline
              J Offline
              JonB
              wrote on 4 Aug 2022, 15:39 last edited by
              #5

              @ELIF
              What queue? std::queue?

              E 1 Reply Last reply 5 Aug 2022, 05:39
              0
              • J JonB
                4 Aug 2022, 15:39

                @ELIF
                What queue? std::queue?

                E Offline
                E Offline
                ELIF
                wrote on 5 Aug 2022, 05:39 last edited by
                #6

                @JonB yes , ofcourse.

                J 1 Reply Last reply 5 Aug 2022, 05:54
                0
                • E ELIF
                  5 Aug 2022, 05:39

                  @JonB yes , ofcourse.

                  J Offline
                  J Offline
                  JonB
                  wrote on 5 Aug 2022, 05:54 last edited by JonB 8 May 2022, 06:55
                  #7

                  @ELIF
                  Then why not say so from the start?! So your question is not connected to Qt C++ data strictures structures after all. You can see the methods of std::queue from the docs:

                  The std::queue class is a container adaptor that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure.

                  The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.

                  Accessors are front() and back() It's a queue. So you cannot access middling elements, and why would you want to if you are choosing to use a queue?

                  However, @JoeCFD's std::dequeue does allow access to middling elements. See Access c++ queue elements like an array for a discussion.

                  1 Reply Last reply
                  2
                  • E Offline
                    E Offline
                    ELIF
                    wrote on 5 Aug 2022, 06:26 last edited by
                    #8

                    @JonB said in QT C++ DATA Structures:

                    strictures

                    Thank you :)

                    1 Reply Last reply
                    0

                    1/8

                    4 Aug 2022, 14:11

                    • Login

                    • Login or register to search.
                    1 out of 8
                    • First post
                      1/8
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved