Quick actions

cmd+k|ctrl+k

Navigation

Languages

Linked List

Snippet info

Language

C

Visibility

public

Author

shaman-rat

Created

2020-07-29T19:20:29Z

Updated

2020-07-29T20:58:34Z

#include <stdio.h>
#include <stdlib.h>

struct link
{
    int val;
    struct link* next;
};
typedef struct link node;

void display(node *start)
{
    node *temp = start;
    while(temp!=NULL)
    {
        printf("%d-->",temp->val);
        temp=temp->next;
    }
    printf("NULL\n");
}

node *create_new_node(int val)
{
    node *result = malloc(sizeof(node));
    result->val=val;
    result->next=NULL;
    return result;
}

node *insert_at_head(node *head, node *node_to_insert)
{
    node_to_insert->next=head;
    return node_to_insert;
}

int main()
{
    node *head=NULL, *temp;
    for(int i=3; i>0; i--)
    {
        temp = create_new_node(i);
        head = insert_at_head(head, temp);
    }
    //link them up
    
    display(head);
    return 0;
}
INFO