help with array in C
-
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.
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 thesort
function.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
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.
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] -
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]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.
-
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.
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] -
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]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.
-
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.
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] -
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.
I understand it as the longest sequence where a(i)<(a(i+1)Watched code never compiles.
-
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.
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" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
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.
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!
-
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.