Facebook
From Whipped Bison, 1 Year ago, written in C.
This paste is a reply to Untitled from Mustard Camel - go back
Embed
Viewing differences between Untitled and Re: Untitled
#include 
#include 

typedef struct Node
{
    int data;
    struct Node* next;
} Node;

Node* head;

void PrintLinkedList()
{
    Node* temp;
    temp = head;
    while(temp !=NULL){
        printf("%d, ", temp->data);
        temp = temp->next;
    }
    printf("\n\n");
}

void InsertAtLast(int userData)
{
    Node* temp = (Node*) malloc(sizeof(Node));
    temp->data = userData;
    temp->next = NULL;
    if(head==NULL)
    {
        head=temp;
        return;
    }

    Node* scout = head;
    while(scout->next != NULL)
    {
        scout = scout->next;
    }
    scout->next = temp;
}

int main()
{
    head = NULL;
    InsertAtLast(5);
    InsertAtLast(7);
    InsertAtLast(2);
    PrintLinkedList();

    return 0;
}