What is the importance of a counter in a linked list? what would happen if one left the counter out of the linked list?

Recommended Answers

All 5 Replies

It makes the sorting, searching, manipulating a list a lot easier
like implementing binary search trees, AVL, heaps, graphs, search algorithms.

what would happen if there was no counter though? would the linked list still perform normally?

what would happen if there was no counter though? would the linked list still perform normally?

well javawise theres a class given that does the counter for you.
But if you want to do it manually (like in C, etc.) the data in each structure acts as the counter for the linked list(usually numeric) so more often than not there's a counter for every linked list. but even if there is an event where no sortable data can be found I guess that as long as each item is connected then yes it should still act like a linked list

what exactly are you suppose to do with the linked list?

Discuss the effect on all the operations if there were not a count variable in the implementation.

This is dealing with linked lists. every time a new node is placed into the list the counter goes up by 1.

looking at the methods of the class all data manipulation of an element using the index should become impossible

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.