Commit 4aa04155 authored by elijah vasquez's avatar elijah vasquez 🦍

SECOND

parent 810c3230
...@@ -49,6 +49,7 @@ void AddNodeToStartOfList(node **ptr_to_start, int value) ...@@ -49,6 +49,7 @@ void AddNodeToStartOfList(node **ptr_to_start, int value)
*ptr_to_start is the contents of the variable head, which is the address of the start of the list. *ptr_to_start is the contents of the variable head, which is the address of the start of the list.
If we change *ptr_to_start (note only one * here) we are changing the contents of head. If we change *ptr_to_start (note only one * here) we are changing the contents of head.
We are changing which node is the first node in the list. We are changing which node is the first node in the list.
*/ */
node *temp = NewNode(value); // Create a new node node *temp = NewNode(value); // Create a new node
...@@ -90,8 +91,39 @@ void AddNodeToEndOfList(node **ptr_to_start, int value) ...@@ -90,8 +91,39 @@ void AddNodeToEndOfList(node **ptr_to_start, int value)
} }
temp->next = new_node; temp->next = new_node;
return; return;
}
int ListLength(node *start) // 1
{
node *temp = NULL;
while (temp->next != NULL)
{
printf("%d\n", temp->val);
temp = temp->next;
}
}
void AddNode(node **ptr_to_start, int value) // 2
{
} }
/*
int main()
{
AddNodeToStartOfList(&head,5);
AddNodeToEndOfList(&head,7);
AddNodeToEndOfList(&head,2);
AddNodeToEndOfList(&head,1);
AddNodeToEndOfList(&head,4);
AddNodeToEndOfList(&head,3);
return 0;
}
*/
/* Exercise Tasks /* Exercise Tasks
1. Write a function int ListLength(node *start) which traverses the list, counts the number of nodes and returns that count. 1. Write a function int ListLength(node *start) which traverses the list, counts the number of nodes and returns that count.
...@@ -124,6 +156,4 @@ AddNodeToEndOfList(&head,1); ...@@ -124,6 +156,4 @@ AddNodeToEndOfList(&head,1);
AddNodeToEndOfList(&head,4); AddNodeToEndOfList(&head,4);
AddNodeToEndOfList(&head,3); AddNodeToEndOfList(&head,3);
*/ */
No preview for this file type
#include <stdio.h>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment