From 0092943c6fdb458c9037d84b9e711ea4a47f3bb1 Mon Sep 17 00:00:00 2001 From: akankshatanwar1701 Date: Mon, 7 Oct 2019 23:03:48 +0530 Subject: [PATCH] Adding LL advanced programs --- Student/Lists Advanced continued.txt | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Student/Lists Advanced continued.txt diff --git a/Student/Lists Advanced continued.txt b/Student/Lists Advanced continued.txt new file mode 100644 index 0000000..6ede075 --- /dev/null +++ b/Student/Lists Advanced continued.txt @@ -0,0 +1,96 @@ + +node* reverser(node*head){ + if(head->next==NULL||head==NULL){ //only one node or no linked list + return head; + } + +//rec case +node*smallhead=reverser(head->next); +node*c=head; +c->next->next=c; +c->next= NULL; +return smallhead; +} + +node* midp(node*head) +{ + if(head==NULL||head->next==NULL) + { + return head; + } + +node*slow=head; +node*fast=head->next; +while(fast!=NULL&&fast->next!=NULL ){ + fast=fast->next->next; + slow=slow->next; +} +return slow; +} + +node* knode(node*head,int k){ + if(head==NULL||head->next==NULL) + { + return head; + } + +node*slow=head; +node*fast=head; +for(int i=0;inext;} +while(fast!=NULL&&fast->next!=NULL ){ + fast=fast->next; + slow=slow->next; +} +return slow; +} + +node* merge(node*a,node*b){ + if(a==NULL){ + return b; + } + else if(b==NULL){ + return a; + } + + node *c; + //compare a and b smaller ele + if(a->data < b->data) + { c=a; + c->next= merge(a->next,b); } + else{ + c=b; + c->next=merge(a,b->next); + + } + return c; +} + +int main() { +node *head=NULL; +node *head2=NULL; + +/*inserth(head,5); +inserth(head,4); +inserth(head,3); +insertt(head,7); +insertm(head,9,3); +print(head); +cout<data; +delm(head,3); +if(searchr(head,4)) { cout<<"ele";} +else{cout<<"no ele";} +print(head); +if(searchi(head,14)) { cout<<"ele";} +else{cout<<"no ele";} +buildl(head); +print(head);*/ +buildl(head); +buildl(head2); +head=merge(head,head2); +print(head); +return 0;}