This commit is contained in:
2026-06-05 01:28:27 +00:00
parent bdde9bd1ca
commit 67b7ced5ba
19 changed files with 276 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
typedef struct node
{
int number;
struct node *next;
} node;
int main(void)
{
node *list = NULL;
// Create List
for (int i = 0; i < 3; i++)
{
int x = get_int("Number: ");
node *n = malloc(sizeof(node));
n->number = x;
n->next = list;
list = n;
if (n == NULL)
{
printf("Malloc failed. \n");
return 1;
}
for (node *ptr = list; ptr !=NULL; ptr = ptr->next)
{
printf("%i\n", ptr->number);
}
node *ptr = list;
while(ptr !=NULL)
{
node *tmp = ptr;
ptr = ptr->next;
free(tmp);
}
}
}