Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. link list

link list

Scheduled Pinned Locked Moved C / C++ / MFC
10 Posts 4 Posters 0 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    paul crescent
    wrote on last edited by
    #1

    hi is there any shortcut to find the mid of the link list without iteration by paul

    C D 2 Replies Last reply
    0
    • P paul crescent

      hi is there any shortcut to find the mid of the link list without iteration by paul

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Which kind of linked list ?

      Cédric Moonen Software developer
      Charting control [v1.4] OpenGL game tutorial in C++

      P 1 Reply Last reply
      0
      • C Cedric Moonen

        Which kind of linked list ?

        Cédric Moonen Software developer
        Charting control [v1.4] OpenGL game tutorial in C++

        P Offline
        P Offline
        paul crescent
        wrote on last edited by
        #3

        hi It is single linked list by paul

        C 1 Reply Last reply
        0
        • P paul crescent

          hi It is single linked list by paul

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Ok but is it your own class or are you using an existing class ? Anyway, there's no support for that by default in a linked list, but you could maybe add it yourself if you wrote the code. For example after adding two elements, you can increase your 'middle' pointer by one (so, make it point to the next element). It becomes more complex when you want to remove elements, in which case I think you will have to recompute it (retrieve the nr of elements in the list and move the middle pointer by half of this number).

          Cédric Moonen Software developer
          Charting control [v1.4] OpenGL game tutorial in C++

          P 1 Reply Last reply
          0
          • C Cedric Moonen

            Ok but is it your own class or are you using an existing class ? Anyway, there's no support for that by default in a linked list, but you could maybe add it yourself if you wrote the code. For example after adding two elements, you can increase your 'middle' pointer by one (so, make it point to the next element). It becomes more complex when you want to remove elements, in which case I think you will have to recompute it (retrieve the nr of elements in the list and move the middle pointer by half of this number).

            Cédric Moonen Software developer
            Charting control [v1.4] OpenGL game tutorial in C++

            P Offline
            P Offline
            paul crescent
            wrote on last edited by
            #5

            hi i have another same question that finding 4th element from the single linked list from last node without iterating list. but i know only the first node address. Is it possible or not . Condition is that i should not change the content of linked list for any reference. by paul

            R 1 Reply Last reply
            0
            • P paul crescent

              hi i have another same question that finding 4th element from the single linked list from last node without iterating list. but i know only the first node address. Is it possible or not . Condition is that i should not change the content of linked list for any reference. by paul

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #6

              Is this an interview question?

              Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]

              P 1 Reply Last reply
              0
              • R Rajesh R Subramanian

                Is this an interview question?

                Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]

                P Offline
                P Offline
                paul crescent
                wrote on last edited by
                #7

                YES :(

                R 1 Reply Last reply
                0
                • P paul crescent

                  YES :(

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #8

                  So, I presume you did not do the interview well. Then why not read up on linked list and learn, rather than insisting on having someone else answer the "same exact question" for you? BTW, Good luck for your next interview.

                  Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]

                  R 1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    So, I presume you did not do the interview well. Then why not read up on linked list and learn, rather than insisting on having someone else answer the "same exact question" for you? BTW, Good luck for your next interview.

                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]

                    R Offline
                    R Offline
                    Rajesh R Subramanian
                    wrote on last edited by
                    #9

                    I am assuming that you voted me 1. But my opinion still stands the same. You'll have to do your stuff. People might answer an interview question here, but that kinda defeats the purpose; your thought process will stop there. If you don't learn things properly and experiment enough on them, you'll never be able to master it. And without mastering it, you won't be able to answer a tricky question. Thanks for the 1 vote, I am not the loser here; I couldn't care less. :)

                    Nobody can give you wiser advice than yourself. - Cicero .·´¯`·->Rajesh<-·´¯`·. Microsoft MVP - Visual C++[^]

                    1 Reply Last reply
                    0
                    • P paul crescent

                      hi is there any shortcut to find the mid of the link list without iteration by paul

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      Anything is possible, especially if you are the author of said list (i.e., your linked list object can keep track of what it perceives as the middle node). While it's common to hold a pointer to the front and back nodes of the list, by their nature, however, a linked list implies iteration.

                      "Love people and use things, not love things and use people." - Unknown

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups