Skip to content

Swapping array elements without extra variable #2436

@xtreme-uz

Description

@xtreme-uz

Is your feature request related to a problem? Please describe.
Small optimizations in the algorithm can lead to large results, for example, when sorting an array, the values are changed and additional memory is required. How to get rid of this extra memory?

Describe the solution you'd like
To swap values without additional memory:
a = 4, b = 7

  1. a = a + b ==> a = 11, b = 7
  2. b = a - b ==> a = 11, b = 4
  3. a = a - b ==> a = 7, b = 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions