Join Raghavendra Dixit for an in-depth discussion in this video Inserting a new node, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Now, let's see how a new node…is inserted in a linked list.…As we have discussed earlier,…the only reference we have in a linked list…is that of the head element,…and one of the common use cases…is to insert a new node at the head,…which means that the new node to be inserted…becomes the head element of the linked list.…Let's see what we mean by that.…Here we have a linked list with a few nodes.…
We want to add five to this linked list.…So we create a new node for it.…To insert this node at the head of the linked list,…we'll need to connect the next node reference…of the new node to the existing head element…of the linked list.…And then, make the head of the linked list…point to the new node.…
And this order in which we connect…the nodes is very important.…For example, if you connect the head object reference…of the linked list to point to the new node first,…what do you think would happen?…Think about it.…Well, what will happen here is that,…the link to the existing head,…which in this case is the node with value one,…
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?
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.