✅ Bug in trying to replicate an unmodified array in a Winforms Sorting Algorithm Application
I have a weird bug in my C# Winform program. Here are the steps before I encountered this error:
1) I put in 100, 10, 1000 in my Number of Values, Min Value and Max value, respectively
2) I pressed generate values in the "Generated Values" tab
3) I press bubble sort in my code and it sorts the array
4) I press clear raw to clear the data in my generated values tab
5) I press redisplay array to show the unmodified array.
But the problem I am encountering is that the array is showing the array that was modified, not the unmodified one. Can someone help me?
13 Replies
Hey, look at the file you shared. Its just the entrypoint of your app, it doesn't actually contain any code to help us debug this at all.
You'll need to show us your code for the
SortingAlgorithm
class
and please do so over at $pasteIf your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
Oh whoops
I sent the wrong file lmao
Ok gimme a sec
Re-read my instructions 🙂
discord cant display long files in-line
BlazeBin - srrklxkdlhsm
A tool for sharing your source code with the world!
great
Can you see it?
Right I see
Sorry I am not used to asking for help on Discord
okay I see the issue
so, the problem is after you sort your array, both
generatedArray
and sortedArray
are actually the same array
not two copies of the same, literally the sameAhhh
the sorting algo you used for bubblesort is an in-place sort, so it doesnt make a copy
you'll need to manually make a copy first, if you want that behaviour
and I can see you more or less tried doing that at line 97
generatedArray.Clone();
but you don't do anything with that clone 🙂Ok yeah I figured out and fixed the issue. Thanks for your help!
👍
feel free to
/close
this thread then