Skip to content

Instantly share code, notes, and snippets.

@CarterZenke
Last active March 3, 2024 05:09
  • Star 1 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save CarterZenke/f9aa3a11b380694560b929d078b1cc94 to your computer and use it in GitHub Desktop.
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node
{
string phrase;
struct node *next;
}
node;
#define LIST_SIZE 2
bool unload(node *list);
void visualizer(node *list);
int main(void)
{
node *list = NULL;
// Add items to list
for (int i = 0; i < LIST_SIZE; i++)
{
string phrase = get_string("Enter a new phrase: ");
// TODO: add phrase to new node in list
// Visualize list after adding a node.
visualizer(list);
}
// Free all memory used
if (!unload(list))
{
printf("Error freeing the list.\n");
return 1;
}
printf("Freed the list.\n");
return 0;
}
bool unload(node *list)
{
// TODO: Free all allocated nodes
return false;
}
void visualizer(node *list)
{
printf("\n+-- List Visualizer --+\n\n");
while (list != NULL)
{
printf("Location %p\nPhrase: \"%s\"\nNext: %p\n\n", list, list->phrase, list->next);
list = list->next;
}
printf("+---------------------+\n\n");
}
@Acoldi
Copy link

Acoldi commented Dec 23, 2023

@wchwawa
Copy link

wchwawa commented Jan 26, 2024

gj

@Thiago1414
Copy link

cool

@Ian-Lohan
Copy link

nice!

@olela28
Copy link

olela28 commented Feb 10, 2024

nice implementation.

@ALargeLordPotato
Copy link

Potato

@JoaquinuX0
Copy link

Good code guys :)

@SomRandomGuy
Copy link

Gj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment