# Thread: general question regarding a function parameter

1. ## 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

InterchangeList( Node*,Node*,List*)

3. 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".

4. Write an algorithm to interchange two list elements stored in a linked list. InterchangeList(position pos1, position pos2, List *list)
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??

5. 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
}

6. For gods sake

If you dont pass in the address of the nodes you want swopped how will you find them?

7. so now...I guess it's safe to assume that at this point, the list has been searched for the two items to swap and thus, the items are stored in pos1 and pos2. Which now makes sense to me. The instructor didn't give us any information up front as to what the preconditions were.

in light of that...yeah, that second question I asked about passing in null pointers....was totally re-freggin-diculous.
Thanks for putting up with my claritin tonight.

Mike

8. So now its a simple problem. Swop the nodes and swop their pointers to ensure the correctness of the list.Or maybe easier.... swop the stored value only?!