If the box pointer '*p' does not match the address of the box to be erased, change it to 'pointer of next box pointer'. First, '**p' is initialized as a 'head pointer pointer'. Torvald's code is that a new pointer '**p' called 'pointer of box pointer' is introduced. The major difference between C101's code and Mr. The if statement that was in the previous code has disappeared, making it a simpler code. However, Torvalds introduced an even better code in a 2016 TED interview. It is certainly possible to delete elements from a list using the code introduced in CS101. If the box to be erased is the first box in the list, process the head pointer to point to the address of the second box from the list as shown below. In the image below, the box with the value '12' has been cleared. The next pointer of the previous box to be deleted will now point to the next box to be deleted, so the box to be deleted will no longer be referenced by any box and will be deleted from the list. If the box to be erased is the first in the list, store the address of the next box after the box to be erased in the head pointer pointing to the beginning of the list.Ī diagram explaining the process when the box to be deleted is not at the beginning of the list looks like this. In the process below, if the box to be erased is not the first in the list, the address of the box following the box to be erased is stored in the next pointer of the box before the box to be erased. Once the cur pointer matches the address of the box to be erased, the next step is to erase the box. It looks like the prev pointer and cur pointer are sliding into the box at the end of the list. Match by moving the cur pointer to the address of the next box until the cur pointer matches the address of the box you want to erase.īelow is a diagram showing the image of the above process. Since a linked list can only trace values from the beginning of the list, first store the address of the box at the beginning of the list in the 'cur' pointer, and initialize the 'prev' pointer with NULL. First, use the following part of the code to search for the 'box you want to erase' from the top of the list. The process performed by the above code is as follows. The code introduced in Stanford University's computer science lecture ' Computer Science 101 (CS101) ' about the process of deleting a certain box from this linked list is as follows. The 'IntList' structure has a variable 'head' that represents the beginning of the list. An 'IntListItem' structure is created with 'value' which is the value itself and 'next' which is a pointer indicating the next value, and a box is generated from the IntListItem structure. The code that implements the linked list in C language is below. Specifically, a linked list is a series of 'boxes' consisting of values such as '4' or '12' and a pointer indicating the 'next value.' In a 2016 TED interview, Torvalds used ``how to implement linked lists'' as an example to explain his thoughts on ``good code.'' A linked list is a list that connects data linearly, and is one of the structures for handling data. Linus Torvalds: The mind behind Linux | TED Talk Mkirchner/linked-list-good-taste: Linus Torvalds' linked list argument for good taste, explained Engineer mkirchner explains Linux developer Linus Torvalds' thoughts on such 'good code'. However, it is also true that there is sometimes a big structural difference between 'readable code' and 'good code'. When programming, it is important to aim for ``easy-to-read code'' by leaving comments properly and giving easy-to-understand variable names. 23:00:00 What does Linus Torvalds, the creator of Linux, think of as 'good code'?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |