bornerwave
Master Member
- Joined
- May 25, 2013
- Messages
- 3,621
- Reaction score
- 37
deleted 
Last edited:
Posting all your codes will not help you. I would recommend that you start learning how to debug by using the most common yet most powerful STANDARD OUT debugging tool.
Learn to be a detective, divide the conquer your codes. Learn to position your debugging statements, make assumption that you think is correct, let the output of the debugging statements assert your claims. Learn to pint down to which part of the code is causing the infinite loop or correct output behaviour. Assert your input and output and see if they stand up to your assumption.
This is the most basic and yet most effective approach to all programming tasks. Anything other thing is superfluous for specific scenarios, even code debuggers.
yes I did do debugging constantly(F5 on microsoft visual studio 2010) to see what were the values of my variables till the extent that I am now constantly checking the values each time I execute a method etc. but the problem is that I don't know why my linking is not working when it should work theoretically when I drew it on a paper. I have been spending 4 days doing the same things over and over again, constantly drawing and drawing, changing the codes which I drew on paper and to no avail which is why I am here for help
Hey bro I'm not a C# guy but your functions are not doing anything. Unless there are other codes you didnt post here your AddMusicCDToFront method is not doing anything.
i. AddMusicCDToFront(MusicCD cd) : Prepend node to linked list
ii. DisplayInventory(): This one very straight forward. Do a for loop with print
iii. RemoveMusicCDAtPosition(int n): Google something like this "remove item from linked list based on index"
iv. MusicCDSwap(int n1, int n2): I'm not sure if there's a direct swap function here but you can get the index of each node and replace one another.
v. SortByAlbumName(): Look for sort function for linked list, confirm will have one.
Get a github/bitbucket account and post your whole code there. It really helps alot for everyone to read your code.
Just curious, uni assignment?
Let me tell you why debugging in the manner you did doesn't quite work for most situation. What you lack in is a trail. You need a trail of what has happened to the point you get a wrong output. Theory on how it should work is a must to know if you are on the right track, but do you have a trail of debugging output that ascertain your assumption ?
Keeping on looking at a dynamically changing variable will lose track of your debugging rhythm. Work backwards from the point you detected an error and see from which point onwards the error starts.
If you want to be able to code well, learn to debug well. Out of 100% of the codes, most good programmers have probably 5-10% more codes, not for doing productive work, but to help in productive coding.
Good try what I show you, use your PRINT TO STDOUT approach in debugging, don't be lazy in output more than necessarily.
beforeNodeA.Link = nodeB;
beforeNodeB.Link = nodeA;
nodeA.Link = nodeB.Link;
nodeB.Link = originalNodeA.Link;
[CODE]
I have done everything until the MusicCDSwap, which is where I am stuck, poly assignment btw
node = ['one', 'two', 'three', 'four', 'five']
def MusicCDSwap(p1, p2, node):
node[p1], node[p2] = node[p2], node[p1]
return node
print node
print MusicCDSwap(1, 3, node)
Returns
['one', 'two', 'three', 'four', 'five']
['one', 'four', 'three', 'two', 'five']
Here's how we do it in python with list. It's actually very simple the idea is to reference the item with index and replace one another
Code:node = ['one', 'two', 'three', 'four', 'five'] def MusicCDSwap(p1, p2, node): node[p1], node[p2] = node[p2], node[p1] return node print node print MusicCDSwap(1, 3, node) Returns ['one', 'two', 'three', 'four', 'five'] ['one', 'four', 'three', 'two', 'five']
Here's how we do it in python with list. It's actually very simple the idea is to reference the item with index and replace one another
Code:node = ['one', 'two', 'three', 'four', 'five'] def MusicCDSwap(p1, p2, node): node[p1], node[p2] = node[p2], node[p1] return node print node print MusicCDSwap(1, 3, node) Returns ['one', 'two', 'three', 'four', 'five'] ['one', 'four', 'three', 'two', 'five']
I have not learn that programming language and I am a beginner so please pardon my comments.
Returns
['one', 'two', 'three', 'four', 'five']
['one', 'four', 'three', 'two', 'five']
Isn't this hard coding? And I am not sure if this is possible in C# because in C#, we have to manually change the pointers here and there to 'swap' the positions of the nodes in the LinkedList.
['one', 'two', 'three', 'four', 'five']
['one', 'four', 'three', 'two', 'five']
are printed return values to show you what is changed. I dont know C# and I dont intend to install monstrous Visual Studio. The idea is all the same, use the index to get the node item and replace them.