From ef5eafefcba007cae75d42c75ee4d3aac10f204b Mon Sep 17 00:00:00 2001 From: Vijay Ingawale <65883107+Vijay-Git03@users.noreply.github.com> Date: Mon, 12 Oct 2020 15:32:49 +0530 Subject: [PATCH] C++ Program to Implement Singly Linked List --- Program to Implement Singly Linked List | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Program to Implement Singly Linked List diff --git a/Program to Implement Singly Linked List b/Program to Implement Singly Linked List new file mode 100644 index 0000000..fa8ddd0 --- /dev/null +++ b/Program to Implement Singly Linked List @@ -0,0 +1,31 @@ +#include +using namespace std; +struct Node { + int data; + struct Node *next; +}; +struct Node* head = NULL; +void insert(int new_data) { + struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); + new_node->data = new_data; + new_node->next = head; + head = new_node; +} +void display() { + struct Node* ptr; + ptr = head; + while (ptr != NULL) { + cout<< ptr->data <<" "; + ptr = ptr->next; + } +} +int main() { + insert(3); + insert(1); + insert(7); + insert(2); + insert(9); + cout<<"The linked list is: "; + display(); + return 0; +}