# general question regarding a function parameter

• 10-13-2002
mlupo
general question regarding a function parameter
Write an algorithm to interchange two list elements stored in a linked list. InterchangeList(position pos1, position pos2, List *list)

I thought you might say the same thing I did. what exactly is the type "position" defined as?

This is a question posed to me in a C course. I know how to swap nodes of a list. That's not the problem here. If the function was written like "InterchangeList(List* list) I'd have no problem.

Can anyone offer a little explaination as to how the first two parameters relate to what's going on inside the function? I wonder if pos 1 and pos 2 are search keys....

I know my question is a little ambiguous...then again, so is the problem at hand.

Mike
• 10-13-2002
Stoned_Coder

InterchangeList( Node*,Node*,List*)
• 10-13-2002
mlupo
Yeah, that's another thing I thougt of too, that each node in the list was of type "position". Which, especially, in a data structures course, does not seem like something that's very a very typical naming scheme for a node type.

Let me ask you this...should I just pass the values for pos1 and pos2 in as NULL pointers?

hehe, I could make it fun and make each node entry a fun word like, "doggie_style" or "missionary".
• 10-13-2002
Stoned_Coder
Quote:

Write an algorithm to interchange two list elements stored in a linked list. InterchangeList(position pos1, position pos2, List *list)
Quote:

Let me ask you this...should I just pass the values for pos1 and pos2 in as NULL pointers?
Have you thought about what you are doing here.Do you know how ridiculous that second statement is??:p
• 10-13-2002
mlupo
Well, why would I want to even care about passing pos1 and pos2 in order to be able to interchange two nodes?
assuming that we have a list that's made up of nodes of type "position". Can't I just declare a few temp nodes inside the function?
inotherwords....why do I even need pos1 and pos2? Would you need that if you were going to swap two nodes in a list?

I'd probably do it this way if I were given the choice as to how to define my function...

InterchangeNodes(List *list){
position pos1;
positiion pos2;

//move some pointers around
}
• 10-13-2002
Stoned_Coder
For gods sake