Triple Ref Pointers - Computerphile | Summary and Q&A

148.0K views
September 1, 2017
by
Computerphile
YouTube video player
Triple Ref Pointers - Computerphile

TL;DR

The video discusses using pointers to pointers in the C programming language to simplify the insertion of items into an alphabetically ordered list.

Install to Summarize YouTube Videos and Get Transcripts

Questions & Answers

Q: How does using pointers to pointers simplify the insertion of items in an alphabetically ordered list?

By using pointers to pointers, you can easily navigate the list without losing track of the previous item, making it simpler to insert items in alphabetical order.

Q: Can you provide an example of using pointers to pointers in the C programming language?

Sure, here's an example:


typedef struct {

   char* name;

} Thing;



void insertItem(Thing** tracer, char* itemName) {

   // Navigate the existing list using the tracer pointer

   Thing* current = *tracer;

   Thing* previous = NULL;

   

   while (current != NULL && strcmp(current->name, itemName) < 0) {

      previous = current;

      current = current->next;

   }

   

   // Create a new item

   Thing* newItem = malloc(sizeof(Thing));

   newItem->name = itemName;

   

   // Update the pointers to insert the new item

   if (previous == NULL) {

      newItem->next = *tracer;

      *tracer = newItem;

   } else {

      previous->next = newItem;

      newItem->next = current;

   }

}

Q: What is the advantage of using pointers to pointers over conventional techniques?

Using pointers to pointers eliminates the need for maintaining a separate pointer to the previous item, simplifying the insertion process. It also allows for easy navigation through the list and prevents losing track of the previous item.

Q: Does the technique of pointers to pointers work in other programming languages as well?

While this technique is specifically demonstrated in C, the concept of pointers to pointers can be applied in other programming languages that support pointers, although the syntax and implementation might differ.

Summary & Key Takeaways

  • The video introduces the concept of using pointers to pointers, also known as the triple ref technique, in the C programming language.

  • By using pointers to pointers, it becomes easier to insert items into an alphabetically ordered list without losing track of the previous item.

  • The technique involves creating a "tracer" pointer that points to a pointer to a thing, allowing for efficient navigation and insertion in the list.

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Explore More Summaries from Computerphile 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on: