Join Raghavendra Dixit for an in-depth discussion in this video Length of a linked list, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Sometimes we may want…to know the length, or the size of the link list.…That is, how many elements are present in a link list?…So let's implement the length method in the link list class.…If there are no nodes in the link list,…that is, the link list is empty,…the length of the link list will be zero, right?…That is straightforward and easy.…Now, consider this link list object.…To find it's length, we can start at the head element,…and keep a counter to count the number of nodes.…
And then we go through all the nodes on the link list…one by one, till it reaches null.…And whenever we move to the next node,…we can increment the counter by one.…So in this example, the length…of the link list is found to be six.…So the length of the link list…is defined by the number of nodes…that are present in the link list.…Now lets implement the link method in the link list class.…So let's write the length method.…
And inside this, we declare a variable…called length, and initialize it to zero.…As we did earlier,…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.