| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Moving all elements up one place in an array https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=5445 |
Page 1 of 1 |
| Author: | skinner36 [ Wed Apr 25, 2018 8:02 am ] |
| Post subject: | Moving all elements up one place in an array |
Hi, Moving array elements up one value to insert a new value at the beginning of the array can be a bit tedious to code. If the array has been switched around so that element 0 is the right most element then an extra degree of frustration is added to the issue. This is how I solved the problem for my current project. Let’s assume we have a dynamic array of 100 structures elements and the rightmost element is 0. Code: Select all The easiest way to do this that I have found is as follows. Code: Select all Done |
|
| Author: | SteveHopwood [ Wed Apr 25, 2018 10:09 am ] |
| Post subject: | Moving all elements up one place in an array |
Done indeed. There is an easier way and that is to use a circular array. Trouble is, I have forgotten how to code one, so I am hoping to attract the attention of one of our resident Coding Genius'. Do one of you have a spare moment? |
|
| Author: | renexxxx [ Wed Apr 25, 2018 11:54 am ] |
| Post subject: | Moving all elements up one place in an array |
If you only ever want to insert a new element at the beginning of the array, John's (skinner36) method is probably the most efficient, as ArraySetAsSeries() is very quick. But, if you need to insert new elements at any given position, you might want to have a look at Ding Li's LinkedList class, which is an implementation of the abstract List class. |
|
| Author: | skinner36 [ Wed Apr 25, 2018 11:58 am ] |
| Post subject: | Moving all elements up one place in an array |
This is only designed to move all of the elements up one to be able to add the new data at the beginning. |
|
| Author: | PeterT [ Wed Aug 22, 2018 12:49 pm ] |
| Post subject: | Moving all elements up one place in an array |
This is a blueprint how it can be done just with logic. It assumes, that the size of the array doesn't change at runtime. But I think this was the intention of the OP. It can be written shorter, but it's harder to read then. Code: Select all |
|
| Author: | KingHigh [ Fri Nov 01, 2019 10:52 pm ] |
| Post subject: | Moving all elements up one place in an array |
Hi All, Here is example code for circular queue which I use in a multipair EA typically 10-14 pairs where all data for trading and indies go thru these queues. Once you get the hang of it, its easy. I believe it is about as fast as it can be but would appreciate any better ideas. KingHigh Code: Select all |
|
| All times are UTC | Page 1 of 1 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|