general question regarding a function parameter

This is a discussion on general question regarding a function parameter within the C Programming forums, part of the General Programming Boards category; Write an algorithm to interchange two list elements stored in a linked list. InterchangeList(position pos1, position pos2, List *list) I ...

  1. #1
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72

    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.

    Thanks in advance,
    Mike
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    how about reading it like this....

    InterchangeList( Node*,Node*,List*)
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    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".
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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??
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    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
    }
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    For gods sake

    If you dont pass in the address of the nodes you want swopped how will you find them?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    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
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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?!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 06:18 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21