2

I hava an array with two types, which the odd index is always TypeA and the even index is always TypeB.

According to the description, the array always has even length, never have odd length.

The data structure of array must be so.

And this structure is from marijnh's orderedmap module.

// array
[A, B, A, B, A, B, ...]

// How to define it's type?
percy507
  • 710
  • 9
  • 11
  • Can you make two arrays, one with type A elements and other with type B elements, and then have a method like get_index which takes an index and then returns array1[index/2] if the index is even and array2[floor(index/2)] otherwise? – Freshman's Dream Nov 25 '21 at 08:17
  • @MDude Ah, sorry. The data structure must be so. – percy507 Nov 25 '21 at 08:21
  • @percy507 why has it to be this way? – Thomas Junk Nov 25 '21 at 08:24
  • 2
    Here you have more similar questions/answers: https://stackoverflow.com/questions/69085069/repeat-multiple-function-arguments/69087323#69087323 , https://stackoverflow.com/questions/68370968/define-a-recursive-array-of-even-length-in-typescript#answer-68373774 , https://catchts.com/rest-tuples#repeated , https://catchts.com/even-length, https://stackoverflow.com/questions/67315596/define-a-type-of-alternating-pairs/69787886#69787886 – captain-yossarian from Ukraine Nov 25 '21 at 08:29
  • @ThomasJunk See the new description. – percy507 Nov 25 '21 at 08:31
  • @captain-yossarian Thanks. I will check that. – percy507 Nov 25 '21 at 08:32
  • @percy507 above solutions should not have odd length. You can also write `MAXIMUM_ALLOWED_BOUNDARY` in a search input and you will get all related solutions – captain-yossarian from Ukraine Nov 25 '21 at 08:34
  • @captain-yossarian OK. I will public it if I can solve this. – percy507 Nov 25 '21 at 08:39

1 Answers1

0

for this type of array it's better to define two arrays first for the first type and second for the second type but for example if it is char and int you can define it as a int and whenever you want to use it as a char in scanf use %d to scan ascii code of that and use %c in printf to print char of it

ilya_m
  • 1