Join Raghavendra Dixit for an in-depth discussion in this video Inserting data in a sorted linked list, part of Introduction to Data Structures & Algorithms in Java.
- [Narrator] Now we will see how we can insert…a new node in a sorted linked list in such a way…that the list remains sorted even after inserting the node.…But before we go to a sorted list,…let's first consider the two cases…where the new node becomes the head of the linked list.…In the first case we look at the empty linked list…where the head element is pointing to a null.…Since there are no other elements this new node…becomes the head element of the linked list.…
In the second case we look at a sorted linked list,…we use a pointer and compare the head…and the new node first.…And we find that the head is bigger than the new node.…So if the list is sorted and the head is bigger…than the new node and by that I mean the value contained…in the head is bigger than the value contained…in the new node, then this new node will become…the new head to keep the list sorted.…So the new node now starts pointing to the current head…as it's new node and the linked list updates…its head element to the new node.…
Now, let's look at the general case of a sorted linked list…
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.