Welcome, guest | Sign In | My Account | Store | Cart
#include <stdlib.h>
#include <stdio.h>

#define null 0

//define the node structure
struct ilist{
    int elem;
    struct ilist *next;

//allocate the memory of target
void createNode(struct ilist **node, int elem){
    struct ilist *temp= malloc(sizeof(struct ilist));
    temp->elem = elem;
    temp->next = null;
    /* we cannot change the value of node, because the subroutine is running on a frame, within a copy of the actual parameters are created
     * if node is changed here, what changed is the copy
     * but we can change the value referenced by node, as the referenced values could be actually be changed.
     * everything is pass by value
    *node = temp;

int main(int argc, char **argv){
    //construct a list
    struct ilist *list = null;
        struct ilist *visitor = null;
    int i = 7;
        if(list == null){
            createNode(&list, i);
            visitor = list;
            struct ilist *temp = null;
            createNode(&temp, i);
            list->next = temp;
            list = temp;
    //visit the list
    while(visitor != null){
        visitor = visitor->next;
    return 0;