Last active
June 8, 2017 00:01
-
-
Save martyworm/2a1b856290fcf7a9a5bb9a8087af0c22 to your computer and use it in GitHub Desktop.
[c] Linked list working as intended now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#define MAXNODES 3 | |
typedef struct node | |
{ | |
int val; | |
struct node* next; | |
}node; | |
int main(void) | |
{ | |
node* first, *newn; | |
int x = 0; | |
//this initializes the nodes with data 1-whatever | |
for(int i = 0; i < MAXNODES; i++) | |
{ | |
if(i == 0) | |
{ | |
first = malloc(sizeof(node)); | |
newn = first; | |
newn->val = x + 1; | |
} | |
else | |
{ | |
newn->next = (node *)malloc(sizeof(node)); | |
newn = newn->next; | |
newn->val = x + 1; | |
} | |
x++; | |
} | |
//addtofront(first, 35); | |
newn = first; | |
printf("\n\n"); | |
while (newn) | |
{ | |
printf("node value: %i\n", newn->val); | |
newn = newn->next; | |
} | |
//printf("\n -- %i -- \n", first->val); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment