From e287602a6686a30df64a184751848d88588aa2c8 Mon Sep 17 00:00:00 2001 From: Subham Choudhury <55877612+SubhamChoudhury@users.noreply.github.com> Date: Thu, 1 Oct 2020 23:41:11 +0530 Subject: [PATCH] Create DisplayinLL --- C++/DisplayinLL | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 C++/DisplayinLL diff --git a/C++/DisplayinLL b/C++/DisplayinLL new file mode 100644 index 0000000..66e40a1 --- /dev/null +++ b/C++/DisplayinLL @@ -0,0 +1,47 @@ +#include +using namespace std; + +class Node{ +public: + int data; + Node* next; +}; + +int main() { + + int A[] = {3, 5, 7, 10, 15}; + + Node* head = new Node; + + Node* temp; + Node* last; + + head->data = A[0]; + head->next = nullptr; + last = head; + + // Create a Linked List + for (int i=1; idata = A[i]; + temp->next = nullptr; + + // last's next is pointing to temp + last->next = temp; + last = temp; + } + + // Display Linked List + Node* p = head; + + while (p != nullptr){ + cout << p->data << " -> " << flush; + p = p->next; + } + + return 0; +}