From 8c54a7b52b043c29506afbe98a1be3fc136e65f0 Mon Sep 17 00:00:00 2001 From: nikhilatkan <61219392+nikhilatkan@users.noreply.github.com> Date: Fri, 21 Feb 2020 02:02:41 +0530 Subject: [PATCH] Taking input through console --- LLtakinginput.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 LLtakinginput.cpp diff --git a/LLtakinginput.cpp b/LLtakinginput.cpp new file mode 100644 index 0000000..814e3d9 --- /dev/null +++ b/LLtakinginput.cpp @@ -0,0 +1,51 @@ +#include +using namespace std; +class node +{ +public: + int data; + node *next; + + node(int d) + { + data=d; + next=NULL; + } +}; + +void insertathead(node*&head,int data) +{ + node*n=new node(data); + n->next=head; + head=n; +} + +void buildlist(node*&head) +{ + int data; + cin>>data; + while(data!=-1) + { + insertathead(head,data); + cin>>data; + } +} +void print(node*head) +{ + while(head!=NULL) + { + cout<data<<"->"; + head=head->next; + } +} + +int main() +{ + node*head=NULL; + buildlist(head); + print(head); + + return 0; + + +}