Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Travesting and Displaying Linked List | Implementing Data Structures
C Structs
course content

Зміст курсу

C Structs

C Structs

1. Introduction to Structs
2. Pointers and Structs
3. Structs and Memory
4. Advanced Structs Usage
5. Implementing Data Structures

bookTravesting and Displaying Linked List

After we have learned how to create and connect nodes, we need to check that such a list works correctly!

To do this, let's write a simple function that will display the entire list.

The function will accept a pointer to the memory area where the head (first) node of the list is stored.

After which a temporary node current will be created, with which we will go through the entire list. The content of the current node will be equal to the content of the current list node.

To iterate through the list, we use the while(){} loop with the necessary condition, namely, until a node is found whose next field is NULL.

Inside the loop, we will display the contents of the data field of the current node and change the next field to move to the next node.

As soon as a node is found whose next field equal NULL, the loop will stop displaying the contents of the nodes and the function will end.

As practice, you will complete a function to dynamically free memory. The function will work using a similar method - iterating through nodes through a loop and “releasing” them.

Note

The temp (temporary) node plays the role of a buffer node. It is needed to temporarily store (and delete) the contents of the current node. If we immediately clear the current node, we will lose connection with the next node, which means access to the list will be lost.

Завдання

  1. Indicate what the current node will be equal to at the beginning of the function;
  2. Specify the correct condition for ending the loop;
  3. Use the necessary function to dynamically free memory.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 5. Розділ 4
toggle bottom row

bookTravesting and Displaying Linked List

After we have learned how to create and connect nodes, we need to check that such a list works correctly!

To do this, let's write a simple function that will display the entire list.

The function will accept a pointer to the memory area where the head (first) node of the list is stored.

After which a temporary node current will be created, with which we will go through the entire list. The content of the current node will be equal to the content of the current list node.

To iterate through the list, we use the while(){} loop with the necessary condition, namely, until a node is found whose next field is NULL.

Inside the loop, we will display the contents of the data field of the current node and change the next field to move to the next node.

As soon as a node is found whose next field equal NULL, the loop will stop displaying the contents of the nodes and the function will end.

As practice, you will complete a function to dynamically free memory. The function will work using a similar method - iterating through nodes through a loop and “releasing” them.

Note

The temp (temporary) node plays the role of a buffer node. It is needed to temporarily store (and delete) the contents of the current node. If we immediately clear the current node, we will lose connection with the next node, which means access to the list will be lost.

Завдання

  1. Indicate what the current node will be equal to at the beginning of the function;
  2. Specify the correct condition for ending the loop;
  3. Use the necessary function to dynamically free memory.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 5. Розділ 4
toggle bottom row

bookTravesting and Displaying Linked List

After we have learned how to create and connect nodes, we need to check that such a list works correctly!

To do this, let's write a simple function that will display the entire list.

The function will accept a pointer to the memory area where the head (first) node of the list is stored.

After which a temporary node current will be created, with which we will go through the entire list. The content of the current node will be equal to the content of the current list node.

To iterate through the list, we use the while(){} loop with the necessary condition, namely, until a node is found whose next field is NULL.

Inside the loop, we will display the contents of the data field of the current node and change the next field to move to the next node.

As soon as a node is found whose next field equal NULL, the loop will stop displaying the contents of the nodes and the function will end.

As practice, you will complete a function to dynamically free memory. The function will work using a similar method - iterating through nodes through a loop and “releasing” them.

Note

The temp (temporary) node plays the role of a buffer node. It is needed to temporarily store (and delete) the contents of the current node. If we immediately clear the current node, we will lose connection with the next node, which means access to the list will be lost.

Завдання

  1. Indicate what the current node will be equal to at the beginning of the function;
  2. Specify the correct condition for ending the loop;
  3. Use the necessary function to dynamically free memory.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

After we have learned how to create and connect nodes, we need to check that such a list works correctly!

To do this, let's write a simple function that will display the entire list.

The function will accept a pointer to the memory area where the head (first) node of the list is stored.

After which a temporary node current will be created, with which we will go through the entire list. The content of the current node will be equal to the content of the current list node.

To iterate through the list, we use the while(){} loop with the necessary condition, namely, until a node is found whose next field is NULL.

Inside the loop, we will display the contents of the data field of the current node and change the next field to move to the next node.

As soon as a node is found whose next field equal NULL, the loop will stop displaying the contents of the nodes and the function will end.

As practice, you will complete a function to dynamically free memory. The function will work using a similar method - iterating through nodes through a loop and “releasing” them.

Note

The temp (temporary) node plays the role of a buffer node. It is needed to temporarily store (and delete) the contents of the current node. If we immediately clear the current node, we will lose connection with the next node, which means access to the list will be lost.

Завдання

  1. Indicate what the current node will be equal to at the beginning of the function;
  2. Specify the correct condition for ending the loop;
  3. Use the necessary function to dynamically free memory.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 5. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
some-alt