From 36f401767c0535d2a59b98b0dff0467e7f6c5a26 Mon Sep 17 00:00:00 2001 From: Siddharth Batra Date: Mon, 1 Oct 2018 00:01:34 +0530 Subject: [PATCH 1/2] Create LinkedList Implementation --- CPP/data-structures/linkedlist.cpp | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 CPP/data-structures/linkedlist.cpp diff --git a/CPP/data-structures/linkedlist.cpp b/CPP/data-structures/linkedlist.cpp new file mode 100644 index 0000000..80fcd71 --- /dev/null +++ b/CPP/data-structures/linkedlist.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; +struct node{ + struct node* next; + int data; +}; +struct node* head=NULL,*temp=NULL,*newn; +void printll() +{ + if(head==NULL) + { + cout<<"Empty List"; + return; + } + else{ + temp=head; + while(temp!=NULL) + { + cout<data<<" "; + temp=temp->next; + } + } +} +int main() +{ + int opt; + cout<<"1 for inserting 2 for printing"; + cin>>opt; + switch(opt) + { + case 1: + while(opt==1) + { + int data; + cin>>data; + newn = (struct node*)malloc(sizeof(struct node)); + newn->data=data; + if(head!=NULL) + { + temp->next=newn; + temp=newn; + temp->next=NULL; + } + else{ + head=temp=newn; + temp->next=NULL; + } + cin>>opt; + } + if(opt==2) + { + printll(); + } + break; + case 2: + printll(); + break; + } + return 0; +} From c34be6674ccc8f99f1ad0687e8b07c86b2ab0856 Mon Sep 17 00:00:00 2001 From: Siddharth Batra Date: Mon, 1 Oct 2018 00:19:37 +0530 Subject: [PATCH 2/2] Update and rename linkedlist.cpp to main.cpp --- .../{linkedlist.cpp => main.cpp} | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) rename CPP/data-structures/{linkedlist.cpp => main.cpp} (64%) diff --git a/CPP/data-structures/linkedlist.cpp b/CPP/data-structures/main.cpp similarity index 64% rename from CPP/data-structures/linkedlist.cpp rename to CPP/data-structures/main.cpp index 80fcd71..74ba821 100644 --- a/CPP/data-structures/linkedlist.cpp +++ b/CPP/data-structures/main.cpp @@ -1,26 +1,8 @@ -#include +#include +#include + using namespace std; -struct node{ - struct node* next; - int data; -}; -struct node* head=NULL,*temp=NULL,*newn; -void printll() -{ - if(head==NULL) - { - cout<<"Empty List"; - return; - } - else{ - temp=head; - while(temp!=NULL) - { - cout<data<<" "; - temp=temp->next; - } - } -} + int main() { int opt;