From cb728a42f107355b6a479401467895517d058a8b Mon Sep 17 00:00:00 2001 From: snehdeep-back Date: Fri, 16 Oct 2020 18:26:32 +0530 Subject: [PATCH] added ll --- linkedlist.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 linkedlist.cpp diff --git a/linkedlist.cpp b/linkedlist.cpp new file mode 100644 index 0000000..937c56c --- /dev/null +++ b/linkedlist.cpp @@ -0,0 +1,46 @@ + +#include +#include + +struct node { + int data; + struct node *next; +}; + +struct node *head = NULL; +struct node *current = NU LL; + + +void printList() { + + struct node *ptr = head; + + printf("\n[head] =>"); + + while(ptr != NULL) { + printf(" %d =>",ptr->data); + ptr = ptr->next; + } + + printf(" [null]\n"); +} + +void insert(int data) { + + struct node *link = (struct node*) malloc(sizeof(struct node)); + link->data = data; + link->next = head; + head = link; +} + +int main() { + insert(10); + insert(20); + insert(30); + insert(1); + insert(40); + insert(56); + + printList(); + return 0; +}