C
C#10mo ago
Gamer1234556

✅ 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
Pobiega
Pobiega10mo ago
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 $paste
MODiX
MODiX10mo ago
If 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!
Gamer1234556
Gamer1234556OP10mo ago
Oh whoops I sent the wrong file lmao Ok gimme a sec
Pobiega
Pobiega10mo ago
Re-read my instructions 🙂 discord cant display long files in-line
Gamer1234556
Gamer1234556OP10mo ago
BlazeBin - srrklxkdlhsm
A tool for sharing your source code with the world!
Pobiega
Pobiega10mo ago
great
Gamer1234556
Gamer1234556OP10mo ago
Can you see it? Right I see Sorry I am not used to asking for help on Discord
Pobiega
Pobiega10mo ago
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 same
Gamer1234556
Gamer1234556OP10mo ago
Ahhh
Pobiega
Pobiega10mo ago
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 🙂
Gamer1234556
Gamer1234556OP10mo ago
Ok yeah I figured out and fixed the issue. Thanks for your help!
Pobiega
Pobiega10mo ago
👍 feel free to /close this thread then
Want results from more Discord servers?
Add your server