summaryrefslogtreecommitdiff
path: root/wk5/lect/insert.c
diff options
context:
space:
mode:
Diffstat (limited to 'wk5/lect/insert.c')
-rw-r--r--wk5/lect/insert.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/wk5/lect/insert.c b/wk5/lect/insert.c
new file mode 100644
index 0000000..de94253
--- /dev/null
+++ b/wk5/lect/insert.c
@@ -0,0 +1,42 @@
+#include <cs50.h>
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+typedef struct node
+{
+ int number;
+ struct node *next;
+} node;
+
+int main(int argc, char *argv[])
+{
+ node *list = NULL;
+
+ for (int i = 1; i < argc; i++)
+ {
+ int number = atoi(argv[i]);
+
+ node *n = malloc(sizeof(node));
+ if (n == NULL)
+ {
+ // free memory
+ return 1;
+ }
+
+ n->number = number;
+ n->next = list;
+ list = n;
+ }
+
+ // Print whole list
+ node *ptr = list;
+ while (ptr != NULL)
+ {
+ printf("%i\n", ptr->number);
+ ptr = ptr->next;
+ }
+}