Tuesday, February 4, 2020

12. Reverse the elements of linked list using Recursive Version

/*****
Reversing content of linked list using Recursion
ReverseusingRecursion() is a function  which returns a pointer to a structure
and it takes NULL in prev node and head in curr.
*****/

void ReverseusingRecursion(struct  node *,struct node *); // Global Declaration of function


 ReverseusingRecursion(NULL,head); // Calling ReverseusingRecursion() function from main()


void ReverseusingRecursion(struct node *prev, struct node *curr)
{
    if(curr)
    {
     ReverseusingRecursion(curr,curr->link);
     curr->link=prev;
    }
    else
    head=prev;
}

11. Reverse the elements of linked list using Iterative Version

/*****
Reverseing content of linked list using Iterative version
Reverseiterative() is a function pointer which returns a pointer to a structure
and it takes head as its initial pointer as parameter
*****/



 struct node *Reverseiterative(struct  node *curr); /// Function cal from main()


 struct node *Reverseiterative(struct  node *curr)
{
  
struct node *prev= NULL;
   struct node *nextnode= NULL;
    while(curr)
    {
     nextnode =curr->link;
     curr->link= prev;
     prev=curr;
     curr=nextnode;
    }
    head=prev;
      printf("value of current node is%d",head);
   return prev;
   }

10. Moving Last Node to the Front

/*****
Moving Last node to the front of linked list
movelastnodetofront()
*****/
// Lets have two pointer (p,q) one will be one step ahead of other;
// the moment one pointer (p) reaches last node ; point its link to head,
// and put null into q ;
movelastnodetofront()
{

 struct node *p,*q;
 p=head;
  while(p->link != NULL)
{
   
    q=p;
    p=p->link;
}
 q->link= NULL;
 p->link=head;
 head=p;
}

9. Delete node after some data value

/*****
deleteatanyindex()
*****/

deleteatanyindex()
{
  struct node *temp=head;
  while(temp->link->data!=3)
  {
     temp=temp->link; 
  }
  struct node *temp1=temp->link;
  temp->link=temp1->link->link;
  free(temp1);
  temp1= NULL;
}

8. Delete Last Node

 /*****
deletelastnode()
*****/
deletelastnode()
{
 struct node *temp=head;
 while(temp->link->link!=NULL)
 {
   temp=temp->link; 
 }
 temp->link->link=NULL;
 free(temp->link);
 temp->link=NULL;
}

7. Delete Node from Begning

/*****
deletnodefrombegning()
*****/
deletnodefrombegning()
{
 struct node *temp=head;
 if(head== NULL)
 {
    printf("THERE IS NO NODE TO DELETE\n"); 
 }
 if(head->link==NULL) // there is only one node
 {
     free(head);
     head=NULL;
 }
 head=head->link;
 free(temp);
}

9_Regular Expressions

Regular expressions- Sometimes in HTML, the developer defines more than one class name ( that’s class input has more than one name Here ...