-2

I have linklist c-program which is working correctly, but a late requirement was that no global variables must be use. So I had to redesigned everything to avoid passing out parameters, but there are parts which is hard to redesign and some of the functions are calling functions and another functions, one example is on the display.

int main() {
        display(&head, &tail);
}

void display(myrec **head, myrec **tail) {
        sort(&*head, &*tail)
        then sort again call function swap
}

My question is how to correctly pass out parameters multiple times. Program is not working correct using sort(&*head, &*tail), there is no syntax error but there are now missing entries on the data. I tried to code everything on the display function just to check and it does, so I am guessing that I am doing something wrong in passing the variables. thanks.

Its not recursion, the head and tail are variables that holds the state of the linklist, so in swap it is change, I also need to reflect the changes to the root caller and other part of the program need the new state of the head and tail.

fyeth fyeth
  • 93
  • 3
  • 10

1 Answers1

0

Re-passing the out parameters to another function is adding "&" again and again. exiting display will make head and tail variable reflect the changes made on the other functions. Not sure if its the best way but it is working.

Ex.

display(&head, &tail);

void display(myrec **head, myrec **tail) {
sort(&*head, &*tail)
}

void sort(myrec **head, myrec **tail) {
swap(&*head, &*tail)
}
fyeth fyeth
  • 93
  • 3
  • 10
  • `&*E` is equivalent to `E` (N1256 6.5.3.2 Address and indirection operators footnote 87), so you cab use `head` and `tail` instead of `&*head` and `&*tail`. – MikeCAT Nov 19 '15 at 00:25