Question

How do you insert an array of linked lists(L) as an argument of a function (in...

How do you insert an array of linked lists(L) as an argument of a function (in pseudocode)?

For example I already have an array of linked lists (L) where each element of this array is the head/ or start of a new linked list.

I then want to traverse each list in the algorithm

e.g. FindMean(how to represent the list here?)

{ here I want to visit the first node of each list in turn, then all the second nodes for each list etc..}

This is what I have, I'm not sure if its representing what I want it to represent:

FindMean(L[Xi..Xm])

{ for( i=1 to m)

{

p = Xi.next

print(p)

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer depends on the language you are using. For example,

in c++,

let us suppose there is a class LinkedList. You made an array of linked list,

LinkedList list[10];

then when calling the function FindMean, you have to pass two things 1. list 2. length of list. So it will be like this,

FindMean(list, 10);

and the function FindMean will look like,

FindMean(LinkedList [], int length)

{ for( i=1; I<length; I++)

{

p = Xi.next

print(p)

}

}

But , if you don't want to pass the length, then you have to use vector instead of array (because vector has property size). eg.

vector<LinkedList> list(10);

FindMean(list);

and FindMean will look like,

FindMean(vector<LinkedList> list)

{ for( i=1; I<list.size(); I++)

{

p = Xi.next

print(p)

}

}

Now for language like python, it is very easy:

just create a list of LinkedList,

lst = [L1, L2, L3, ...]

and call the FindMean Function by just calling:

FindMean(lst)

and FindMean wiil look like,

def FindMean(lst)

   for l in lst:

   p = Xi.next

   print(p)

Add a comment
Know the answer?
Add Answer to:
How do you insert an array of linked lists(L) as an argument of a function (in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT