课程: Java Algorithms
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Linked list algorithms: Delete back half of a linked list - Java教程
课程: Java Algorithms
Linked list algorithms: Delete back half of a linked list
- [Instructor] With data structures built from scratch, we can create more complex algorithms. With data structures built from scratch, we can create more complicated algorithms that manipulate how our data is stored. For example, let's say we want to delete the back half of a linked list. It would be nice to have access to those next pointers because all we would have to do is set the appropriate next pointer, equal to null. We can do this using our custom linked list structure. Inside the class, we have a head node and the node contains a next pointer and some data. In the main method of our algorithms class, we create a linked list and display its contents. With this sample data in place, let's create an algorithm that deletes the back half of this list. We'll put this in the custom linked list class. This will modify the linked list, so it's return value is equal to void. For this algorithm, we'll need to iterate through the linked list. And if we reach the middle node, we'll set…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。
内容
-
-
-
-
-
What is a linked list?2 分钟 18 秒
-
(已锁定)
Using the built-in linked list data structure in Java4 分钟 16 秒
-
(已锁定)
Create a custom data structure for linked list algorithms3 分钟 32 秒
-
(已锁定)
Linked list algorithms: Delete back half of a linked list4 分钟
-
(已锁定)
Solution: Sum contents of a linked list1 分钟 36 秒
-
-
-
-
-