From the course: Master C Language Pointers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Adding structures - C Tutorial
From the course: Master C Language Pointers
Adding structures
- [Instructor] To add or insert a new structure into an existing linked list, you update the pointer of the previous structure. First allocate the new structure. Copy the previous structure's next member into the new structure. Then update the previous structure's next member to reference the new structure. This code builds a five structure linked list. It's created in the main function in a for loop down at line 62. After the list is output at line 84, a new structure is inserted after the second structure in the list. The while loop bases its search on the id member of each structure. Pointer current references the second structure when this loop is complete. The new structure is allocated at line 102 by using the temp variable. The structure is filled starting at line 105. For the structure's next member, the current structure's next member pointer is copied. This is the first step to inserting the structure.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Understanding a linked list2m 20s
-
(Locked)
Implementing a linked list3m 36s
-
(Locked)
Removing structures4m 3s
-
(Locked)
Adding structures3m 3s
-
(Locked)
Creating a double-linked list2m 57s
-
(Locked)
Saving a linked list3m 4s
-
(Locked)
Challenge: Manage a linked list2m 13s
-
(Locked)
Solution: Manage a linked list2m 26s
-
-