Skip to content

Instantly share code, notes, and snippets.

@siscia
Created November 4, 2013 23:20
Show Gist options
  • Save siscia/7311055 to your computer and use it in GitHub Desktop.
Save siscia/7311055 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
struct listnode
{
void * element;
struct Node * next;
};
typedef struct listnode ListNode;
typedef ListNode * ListNodePtr;
void * add_node(ListNodePtr *node, void * element){
ListNodePtr newNode;
newNode = malloc( sizeof ( ListNode ) );
if(newNode != NULL){
newNode->element = element;
newNode->next = node;}
return newNode;
}
int main(){
ListNodePtr a, b, c, d, current;
int g = 4, t = 7, k = 8, i, POI[10] = {23};
for(i=1;i<10;i++)
POI[i] = i;
a = add_node(NULL, &g);
c = add_node(a, &k);
b = add_node(c, &t);
d = b;
for(i=0;i<10;i++)
d = add_node(d, &POI[i]);
current = d;
while(current != NULL){
printf("node %d\n", *((int*)current->element));
current = current->next;}
return 1;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment