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. help with array in C

help with array in C

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsdata-structureshelptutorialquestion
13 Posts 7 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.
  • F Farraj

    Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

    F Offline
    F Offline
    Farraj
    wrote on last edited by
    #3

    hi, thanks for ur reply

    Farraj wrote:

    the largest part that gives me A[i] < A[i+1] < A[i+2]..

    i mean the largest sequence of a[i] < a[i+1]..like 2 3 4 5

    1 Reply Last reply
    0
    • F Farraj

      Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #4

      I guess you need to sort in ascending order. You can either code any of the sorting algorithm. Or You can put the array into a vector container and then call the sort function.

      «_Superman_» I love work. It gives me something to do between weekends.
      Microsoft MVP (Visual C++)

      1 Reply Last reply
      0
      • F Farraj

        Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #5

        And what is your doubt about (just a couple of loops would suffice, at first sight)? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        L 1 Reply Last reply
        0
        • C CPallini

          And what is your doubt about (just a couple of loops would suffice, at first sight)? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #6

          one loop is all it takes, this is an O(n) job. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Prolific encyclopedia fixture proof-reader browser patron addict?
          We all depend on the beast below.


          C 1 Reply Last reply
          0
          • L Luc Pattyn

            one loop is all it takes, this is an O(n) job. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Prolific encyclopedia fixture proof-reader browser patron addict?
            We all depend on the beast below.


            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #7

            Yes, I realize you may complete it with just one loop and pair of variables. :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            L 1 Reply Last reply
            0
            • C CPallini

              Yes, I realize you may complete it with just one loop and pair of variables. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #8

              so you did read the hint[^] :laugh:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              C 1 Reply Last reply
              0
              • L Luc Pattyn

                so you did read the hint[^] :laugh:

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Prolific encyclopedia fixture proof-reader browser patron addict?
                We all depend on the beast below.


                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #9

                Of course. :-D Now, plz gimme codez! (urgentz)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                1 Reply Last reply
                0
                • L Luc Pattyn

                  you again?

                  Farraj wrote:

                  the largest part

                  define "largest part". is it the part holding the largest value; or having the most elements; or having the largest sum of elements; or... whichever it is, reading the array sequentially will solve it; just calculate the current merrit, and remember the best so far. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  Prolific encyclopedia fixture proof-reader browser patron addict?
                  We all depend on the beast below.


                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #10

                  I understand it as the longest sequence where a(i)<(a(i+1)Watched code never compiles.

                  1 Reply Last reply
                  0
                  • F Farraj

                    Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #11

                    bubble sort and binary search :-)

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    1 Reply Last reply
                    0
                    • F Farraj

                      Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

                      S Offline
                      S Offline
                      Stuart Dootson
                      wrote on last edited by
                      #12

                      So you want to find the longest sub-sequence where the numbers are in ascending order? I would loop through the array from item 1 to the last item, checking if the current item is larger than the previous item. You need to maintain the current ordered sequence length, which you would reset if you detect an item that's smaller than the previous one, and increment if the current item is bigger than the previous one. You also need to record the maximum ordered sequence length, which you would set to the current ordered sequence length when the current one is bigger than the maximum.

                      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!

                      1 Reply Last reply
                      0
                      • F Farraj

                        Hello, i need help with some C code. lets say i have an array ..for example {1,3,2,5,10,11,8,7,9} i need find the the largest part that gives me A[i] < A[i+1] < A[i+2].. in this case its {2,5,10,11) and the algorithm should return me the j that started this series of number (j=2) what should i do? i'd be glad if anyone can help me reaching the answer.

                        F Offline
                        F Offline
                        Farraj
                        wrote on last edited by
                        #13

                        Thanks for ur replies i've made one loop for the array that checks if v[i]

                        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