Question

Write a pseudo code for a linked list get() operation

Write a pseudo code for a linked list get() operation

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

"""""""""""""In case of doubt please comment """""""""""""""""""""""

Now our get function will return the nth element from the linked list.

Algorithmic procedure:

procedure get (start, index)

1) initialize current_element=0;

2) current_pointer = start \\ initializing current pointer to start of the linked list

2) Now run a loop for through the linked list starting from start address;

a) If current_element == index return current node

b) else:

i)  current_element = current_element+1

ii) change current to point to next of the current

""""""""C++ code"""""""""""""""""""""""""""

int get (Node* start, int index)

{   Node* current_pointer = start; //it will show point the current node

    int current_element = 0;

    while (current_pointer != NULL)

    {

        if (current_element== index)

            return(current_pointer -> data);

        count++;

        current_pointer = current_pointer->next;

    }

  

Add a comment
Know the answer?
Add Answer to:
Write a pseudo code for a linked list get() operation
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
ADVERTISEMENT