- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
AI, Data Science, & Programming for Small Business Applications & Large Enterprises › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3: [Algorithms] – Linear Search, Binary Search, Bubble Sort, Selection Sort, Recursion, Merge Sort › Sorting arrays: Swap with a temporary array address?
Tagged: arrays, sorting arrays
This is the array that needs to be sorted in ascending order:
Address | Value |
---|---|
a0 | 8 |
a1 | 7 |
a2 | 6 |
a3 | 2 |
a4 | 9 |
There will be three scenarios:
Either a0 = a1 or a0 > a1 or a0 < a1
It appears there will be a swap from a0 to a1 as a0 > a1.
One way to do swap I have earlier came across is:
a0 = at
at = a1
a1 = at
Will the above process be applicable also here.
Also, how to have at? Can a new address at be created initially holding say 0?
Reply
Yes it’s applicable.
tmp = A[0];
A[0] = A[1];
A[1] = tmp;
[learn_press_profile]