C# Assignment help needed

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
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.
 

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
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
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
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

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.
 

stupidbodo

Junior Member
Joined
Mar 26, 2010
Messages
89
Reaction score
0
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?
 
Last edited:

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
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?

I have done everything until the MusicCDSwap, which is where I am stuck, poly assignment btw
 

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
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.

yes I did do the trial method, in which I simulate a scenario to test my program, I eventually found the problem to which line of code is wrong only, but I cannot understand why it is wrong you see, it should be correct...

Eventually I gave up, which is why all the linking codes are gone.., i will add it back in awhile
Code:
  beforeNodeA.Link = nodeB;
            beforeNodeB.Link = nodeA;
            nodeA.Link = nodeB.Link;
            nodeB.Link = originalNodeA.Link;
[CODE]
 
Last edited:

stupidbodo

Junior Member
Joined
Mar 26, 2010
Messages
89
Reaction score
0
I have done everything until the MusicCDSwap, which is where I am stuck, poly assignment btw

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']
 

a&w_rootbeerz

High Supremacy Member
Joined
Jul 21, 2013
Messages
45,067
Reaction score
4
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']

Hey you are actually good. You shouldn't call yourself stupidbodo. Don't put yourself in this category lah. Not good for you. Lol
 

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
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.
 

stupidbodo

Junior Member
Joined
Mar 26, 2010
Messages
89
Reaction score
0
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.
 

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
['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.

my index are kind of screwed up as welll.. the value of nodeA should be beforeNodeA but it is not, idk why.
 

bornerwave

Master Member
Joined
May 25, 2013
Messages
3,621
Reaction score
37
guys, i think i have solved the question myself, and with a little help from the logic you guys gave, thanks for providing assistance
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top