A Writer by quotes, Web Developer by Brain, Indian by Heart,Music Lover by Soul, Inspirer by Words.

Home Top Ad

INSTAGRAM FOLLOW ME OR ASK ME ANY HELP 1. FOLLOW MY PAGE 2.  MY PROFILE LL - Dup Element In a given LinkedList (where each no...

Learning Module on Linked List - C&JAVA

Related image

INSTAGRAM FOLLOW ME OR ASK ME ANY HELP
LL - Dup Element

In a given LinkedList (where each node has a character), there is one character which appears twice. Find a function to find the character and return it. Input: h->e->l->l->o->NULL Output : 'l' Input: a->s->d->f->g->h->j->a->NULL Output: 'a' //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.


#include "common.h"
#include
char func(struct SchNode * head){
char ch  = '\0';
// WRITE YOUR CODE HERE
    if(head==NULL)
    return NULL;
    struct SchNode* ptr=head;
   while(ptr!='\0')
   {
       struct SchNode* next=ptr->nextNode;
       while(next!='\0')
       {
            if(ptr->ch==next->ch)
            {
             return ptr->ch;
            }
           next=next->nextNode;
       }
   ptr=ptr->nextNode;
}
return ch;

}

Given a LinkedList (where each node has a character) insert a given character at the specified location Input: Input : H->e->l->l->o->NULL Location: 3 (if the location is beyond LinkedList length, ignore) CharacterToInsert: 'm' Output: H->e->m->l->l->o->NULL // here is the definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.

#include "common.h" #include "ExpCUtils.h" struct SchNode * func(struct SchNode * head, int index, char ch) { // WRITE YOUR CODE HERE if(head==NULL) { return NULL; } else { struct SchNode * prev=head; struct SchNode * next=NULL; struct SchNode * head1; head1=(struct SchNode*)malloc(sizeof(struct SchNode)); head1->ch=ch; head1->nextNode=NULL; int i=1; if(index==1) { head1->nextNode=head; head=head1; } else { while(index!=i) { if(prev==NULL) return head; else { i++; next=prev; prev=prev->nextNode; } } next->nextNode=head1; head1->nextNode=prev; return head; }} }
Find the intersection of two given LinkedList (where each node has a character). Return the LinkedList which has character which appears in both LinkedList (same sequence order as LinkedList1). Input: LinkedList1: H->e->l->l->o->NULL LinkedList2: w->o->r->l->d->NULL Output: l->o->NULL Input: LinkedList1: h->i->NULL LinkedList2: b->y->e->NULL Output: null // here is the definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
In JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public SchNode func(SchNode head1, SchNode head2) { // write your code here if(head1==null&&head2==null) return null; if(head1==null) return null; if(head2==null) return null; SchNode t=null; SchNode r=null;int i=0,j=0; SchNode temp1=head1; SchNode temp2=head2; while(temp1!=null) { j=0; temp2=head2; while(temp2!=null) { if(i==0&&temp1.ch==temp2.ch) { char c=temp1.ch; t=new SchNode(c); //t.ch=temp1.ch; t.nextNode=null; temp2.ch='@'; i=1; r=t; break; } else if(temp1.ch==temp2.ch) { j=1; temp2.ch='@'; break; } temp2=temp2.nextNode; } if(i==1&&j==1) { char c=temp1.ch; SchNode y=new SchNode(c); y.nextNode=null; t.nextNode=y; t=y; } temp1=temp1.nextNode; } return r; } }
Number is given in a LinkedList (where each node has one digit), find if it is jumper number, where the absolute difference consecutive digits is 1 Input: 2->3->4->5->4->3->4->3->2->1->NULL Output: true Input: 2->3->4->5->3->4->NULL Output: false // here is the definition of SintNode public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public boolean func(SintNode head) { if(head==null) return false; SintNode t=head; int c=0,j=0; while(t.nextNode!=null) { c++; if(((t.num-t.nextNode.num)==1)||(t.num-t.nextNode.num)==-1) j++; t=t.nextNode; } if(j==c) return true; else return false; } }

Given LinkedList where each node has an integer, replace every element with least greatest element on the right Input: 10->12->5->40->21->70->1->49->37->NULL Output: 12->21->21->49->37->70->37->49->37->NULL // here is the definition of SintNode public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SintNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public SintNode func(SintNode head) { if(head==null) return null; SintNode t=head,tt=head; int j=0; int min=9999; while(t!=null) { min=9999; SintNode t1=t; while(t1!=null) { if(t.numt1.num) min=t1.num; } t1=t1.nextNode; } if(min!=9999) t.num=min; t=t.nextNode; } return head; } }
Given a linkedlist, where each node has a character, find the character which appeared the maximum time. If you have multiple character as result, return the first character in that list. Input: h->e->l->l->o-> ->w->o->r->l->d->NULL Output : 'l' Input: y->e->l->h->a->h->a->NULL Output: 'h' // here is the definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public char func(SchNode head) { char c='\0'; if(head==null) return c; SchNode tr=head; SchNode trr=null; char chh=0; int i=0; while(tr!=null) {int min=0; trr=tr; while(trr!=null) { if(tr.ch==trr.ch) { min++; } if(min>i){chh=tr.ch; i=min;} trr=trr.nextNode; } tr=tr.nextNode; } // write your code here return chh; } }
Given two LinkedList, where each list denotes an number where each node has one digit, return us a LinkedList which is the sum of these two numbers. Please DO NOT convert to integers to perform the addition. Input: LinkedList1: 1->4->5->NULL LinkedList2: 3->9->NULL Output: 1->8->4->NULL // here is the definition public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SintNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA
package LinkedList.AddLL; /** * Created by Sumit Jain on 7/10/2016. */ public static void main(String args[]){ AddLinkedListForwardOrder l = new AddLinkedListForwardOrder(); Node h1 = new Node(1); h1.next= new Node(1); h1.next.next = new Node(1); h1.next.next.next = new Node(7); System.out.print("First Number : "); l.display(h1); Node h2 = new Node(9); h2.next= new Node(9); h2.next.next = new Node(9); h2.next.next.next = new Node(9); System.out.print("\n Second Number : "); l.display(h2); Node x = l.add(h1, h2); System.out.print("\n Addition : "); l.display(x); } } class Node{ public int data; public Node next; public Node(int data){ this.data = data; this.next = null; } } return data;}}
Count the number of pairs in LinkedList (where each node has a integer) whose sum equals given sum (all elements are unique) Input: 0->2->5->7->4->6->10->20->-10->NULL Sum: 10 Output : 3 [(0, 10), (4, 6), (20, -10)] // here is the definition of SintNode public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SintNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public int func(SintNode head, int sum) { if(head==null) return 0; int c=0; SintNode r=head,t=head; while(r.nextNode!=null) { t=r.nextNode; while(t!=null) { if(r.num+t.num==sum) c++; t=t.nextNode;}r=r.nextNode; } return c; } }
IN C LANGUAGE:-
#include "common.h" #include #include "ExpCUtils.h" int func(struct SintNode * input, int sum){ int num = 0,count=0; struct SintNode* n=input; while(n->nextNode!='\0') { struct SintNode *n1=n->nextNode; while(n1!='\0') { if((n->num+n1->num)==sum) { count++; } n1=n1->nextNode; } n=n->nextNode; } return count; }
Given a LinkedList (where each node has a character) remove duplicates characters and maintain the same order Input: H->e->l->l->o->w->o->r->l->d->h->i->NULL Output: H->e->l->o->w->r->d->h->i->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public SchNode func(SchNode head){ if(head==null) return null; SchNode t=head; SchNode t1=null,m=null,r=null,b=head,c=null,tq=null; while(t.nextNode!=null) { m=t.nextNode; while(m!=null) { if((t.ch==m.ch)&&(t.ch!='*')) { m.ch='*'; } m=m.nextNode; } t=t.nextNode; } while(b!=null) { if(b.ch!='*') { if(c==null){ SchNode anil=new SchNode(b.ch); anil.nextNode=null; c=anil; tq=c; } else { SchNode anil=new SchNode(b.ch); anil.nextNode=null; c.nextNode=anil; c=anil; } } b=b.nextNode; } return tq; } }
Given a LinkedList (where each node has a character) remove the given character Input: Input String: H->e->l->l->o->NULL CharacterToRemove: 'l' Output: H->e->o->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include "ExpCUtils.h" struct SchNode * func(struct SchNode * head, char ch) { struct SchNode *x=head,*temp1,*n; int f=0; while(x!=NULL) { if((x->ch)!=ch) { if(f==0){ temp1=(SchNode*)malloc(sizeof(SchNode)); temp1->ch=x->ch; f=1; n=temp1; } else { SchNode*N=(SchNode*)malloc(sizeof(SchNode)); N->ch=x->ch; n->nextNode=N; n=N; } } x=x->nextNode; } if(f==0) return NULL; else return temp1; }
Given a input string (inputStr1) and reference string (inputStr2) as a LinkedLink, where each Node has a character, remove all the occurrence of character of reference string in the input string Input LinkedList: H->e->l->l->o->w->o->r->l->d->h->i->NULL Deletion String: l->h->e->NULL Output String: H->o->w->o->r->d->i->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include #include "ExpCUtils.h" struct SchNode * func(struct SchNode * head1, struct SchNode * head2){ struct SchNode *temp1,*n,*x,*y; x=head1; y=head2; int f=0; while(x!=NULL) { y =head2; while(y!=NULL) { if((x->ch)==(y->ch)) { x->ch='#'; } y=y->nextNode; } x=x->nextNode; } x=head1; while(x!=NULL) { if(x->ch!='#') { if(f==0){ temp1=(SchNode*)malloc(sizeof(SchNode)); temp1->ch=x->ch; f=1; n=temp1; } else { SchNode*N=(SchNode*)malloc(sizeof(SchNode)); N->ch=x->ch; n->nextNode=N; n=N; } } x=x->nextNode; } if(f==0) return NULL; else return temp1; }
Given a string as LinkedList (where each node has a character), reverse the LinkedList Input: Input String: M->i->k->e->NULL Output: e->k->i->M->NULL Input String: b->r->e->a->k->NULL Output: k->a->e->r->b->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include "ExpCUtils.h" struct SchNode * func(struct SchNode * head){ struct SchNode *temp1=NULL,*temp2=head,*temp3,*head1; while(temp2!=NULL) { temp3=temp2->nextNode; temp2->nextNode=temp1; temp1=temp2; temp2=temp3; } temp2=head1; return head1; }
Reverse a string (given a linkedlist, where each node has a character) in a group of given size. Every group of string of given size should be reversed. Input: h->e->l->l->o-> ->m->a->s->t->e->r->4->5->NULL Size: 3 Output: l->e->h-> ->o->l->s->a->m->r->e->t->5->4->NULL Input: t->h->a->n->k-> ->y->o->u-> ->b->y->e->NULL Size: 2 Output: h->t->n->a-> ->k->o->y-> ->u->y->b->e->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h"
#include "ExpCUtils.h"

struct SchNode * func(struct SchNode * head, int size) {
   if(size==0)
   return head;
   else if(head==NULL)
   return NULL;
   else
   {

   struct SchNode* current = head;
   struct  SchNode* next = NULL;
   struct SchNode* prev = NULL;
   int count = 0;  
   
   while (current != NULL && count < size)
   {
       next  = current->nextNode;
       current->nextNode = prev;
       prev = current;
       current = next;
       count++;
   }
   
   if (next !=  NULL)
      head->nextNode = func(next, size);

   return prev;
}
}

Given a LinkedList, where each node has character, rotate the LinkedList by given number 'n' Input: a->b->c->d->e->f->g->h->NULL n: 4 Output: e->f->g->h->a->b->c->d->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include "ExpCUtils.h" struct SchNode * func(struct SchNode * head, int n) { if(head==NULL) { return NULL; } else { struct SchNode *temp,*pre=NULL;int i; for(i=0;inextNode!=NULL) { pre=temp; temp=temp->nextNode; } temp->nextNode=head; pre->nextNode=NULL; head=temp; }}return head; }
Given a LinkedList, where each node has character, rotate the LinkedList by given number 'n' Input: a->b->c->d->e->f->g->h->NULL n: 4 Output: e->f->g->h->a->b->c->d->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-

#include "common.h"

#include "ExpCUtils.h"

struct SchNode * func(struct SchNode * head, int n)
{
    if(head==NULL)
    {
        return NULL;
    }
    else
    {
    struct SchNode *temp,*pre=NULL;int i;
    for(i=0;i
    {
        temp=head;
            while(temp->nextNode!=NULL)
            {
                pre=temp;
                temp=temp->nextNode;
            }
            temp->nextNode=head;
            pre->nextNode=NULL;
            head=temp;
        }}return head;
    }
For a given LinkedList, which has character and the number of times the character appeared, decode to the full string. During decoding if the character appear only once, then no number will be next to that character. Input: a->5->b->r->3->NULL Output: a->a->a->a->a->b->r->r->r->NULL Input: a->1->0->b->r->3->a->3->NULL Output: a->a->a->a->a->a->a->a->a->a->b->r->r->r->a->a->a->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include "ExpCUtils.h" #include struct SchNode * func(struct SchNode * str){ SchNode *temp,*head,*n1,*t2; temp=str; int n,f=0; char t; while(temp!=NULL){ t2=temp->nextNode; if(isdigit(temp->ch)){ if(t2!=NULL&&isdigit(t2->ch)) n=((temp->ch)-48)*10+(t2->ch)-48; else n=int(temp->ch)-48; } if(isalpha(temp->ch)) { if(f==0){ head=(SchNode*)malloc(sizeof(SchNode)); head->ch=temp->ch; n1=head; f=1; t=temp->ch; } else { SchNode *newNode=(SchNode*)malloc(sizeof(SchNode)); newNode->ch=temp->ch; n1->nextNode=newNode; n1=newNode; t=temp->ch; } } while(n>1){ SchNode *newNode=(SchNode*)malloc(sizeof(SchNode)); newNode->ch=t; n1->nextNode=newNode; n1=newNode; n--; } temp=temp->nextNode; } return head; }
For a given input LinkedList (where each node is character), count the contiguous characters and represent them in integers. If the contiguous count is 1, you need not add the integer. Input: a->a->a->a->a->b->r->r->r->NULL Output: a->5->b->r->3->NULL Input: a->a->a->a->a->a->a->a->a->a->b->r->r->r->a->a->a->NULL Output: a->1->0->b->r->3->a->3->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN JAVA:-
import com.expanion.code.evalution.*; public class Answer implements QuestionInterface { @Override public SchNode func(SchNode str){ SchNode temp; char ch; int count=0,c=0; temp=str; SchNode v=null,u=null,t=null; while(temp!=null) { count=1; ch=temp.ch; if(c==0) { v=new SchNode(temp.ch); v.ch=temp.ch; t=v; c=1; } else { u=new SchNode(temp.ch); u.ch=temp.ch; t.nextNode=u; t=u; } while(temp.nextNode!=null&&temp.nextNode.ch==ch) { count++; temp=temp.nextNode; } if(count>9) { u=new SchNode(temp.ch); u.ch=(char)(count/10+48); t.nextNode=u; t=u; u=new SchNode(temp.ch); u.ch=(char)(count%10+48); t.nextNode=u; t=u; } else if(count!=1) { u=new SchNode(temp.ch); u.ch=(char)(count+48); t.nextNode=u; t=u; } temp=temp.nextNode; } return v; } }
Given an LinkedList (where each node has integer) find the second largest element (where array has only distinct elements) Input: 2->10->11->20->-5->40->60->90->1->100->NULL Output: 90 // here is the definition of SintNode public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SintNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
#include "common.h" #include "ExpCUtils.h" #include int func(struct SintNode * input){ struct SintNode *a=input; struct SintNode *a1=NULL;int temp=0; while(input!='\0') { a1=input->nextNode; while(a1!='\0') { if(input->numnum) { temp=input->num; input->num=a1->num; a1->num=temp; } a1=a1->nextNode; } input=input->nextNode; } return a->nextNode->num; }
Given a input two LinkedList (inputlist1) and (inputlist2), merge these two LinkedList by combining elements of same index Input String: H->e->l->l->o->NULL Deletion String: 1->2->3->NULL Output String: H->1->e->2->l->3->l->o->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language
IN C

#include "common.h"

#include "ExpCUtils.h"

struct SchNode *  func(struct SchNode*head1, struct SchNode*head2) {
if(head1==NULL&&head2==NULL)
return NULL;
else if(head1!=NULL&&head2==NULL)
return head1;
else if(head1==NULL&&head2!=NULL)
return head2;
else
{
 struct SchNode *t1=head1;
 struct SchNode *t2=head2;
 struct SchNode *head=NULL;
 struct SchNode *last=NULL;
 while(t1!=NULL||t2!=NULL)
 {
 if(t1!=NULL)
 {
struct SchNode *n=(struct SchNode *)malloc(sizeof(struct SchNode));
n->ch=t1->ch;
  if(head==NULL)       
   {
       head=n;
       last=n;
   }      
  else
  {
     last->nextNode=n;
     last=n;
       }
     t1=t1->nextNode;
 }
if(t2!=NULL)
{
struct SchNode *n=(struct SchNode *)malloc(sizeof(struct SchNode));
n->ch=t2->ch;
  if(head==NULL)       
   {
       head=n;
       last=n;
   }      
  else
  {
     last->nextNode=n;
     last=n;
       }
     t2=t2->nextNode;
}}
 return head;  
} }
Given a LinkedList (each node is a character), split the LinkedList to half and reverse each half Input: Input String: M->i->k->e->NULL Output: i->M->e->k->NULL Input String: b->r->e->a->k->NULL Output: r->b->e->k->a->NULL //here is the class definition of SchNode public class SchNode { public char ch; public SchNode nextNode; public SchNode(char ch){ this.ch = ch; } } //Here is the Definition of SchNode for C Language struct SchNode { char ch; struct SchNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C:-
#include "common.h" #include "ExpCUtils.h" struct SchNode * func(struct SchNode * str) { //WRITE CODE HERE if(str==NULL) { return NULL; } SchNode *tor,*har,*tmp; int cnt; tmp=str; tor=str; har=tor->nextNode; SchNode *ptr1,*prev=NULL,*next=NULL,*head=NULL,*prev1=NULL,*next1,*head1=NULL,*fin=NULL,*ptr2; SchNode *next3,*prev3=NULL; int c=0; while(tmp!=NULL) { tmp=tmp->nextNode; c++; } tmp=str; if(c==1) return str; if(c%2==0) { while(har && har->nextNode) { tor=tor->nextNode; har=har->nextNode->nextNode; } ptr1=tor->nextNode; tor->nextNode='\0'; har=ptr1; while(har!=NULL) { next=har->nextNode; har->nextNode=prev; prev=har; har=next; } head=prev; tor=str; while(tor!=NULL) { next1=tor->nextNode; tor->nextNode=prev1; prev1=tor; tor=next1; } head1=prev1; fin=head1; while(fin->nextNode!=NULL) { fin=fin->nextNode; } fin->nextNode=head; fin->nextNode=head; return head1; } else if(c%2!=0) { while(har && har->nextNode) { tor=tor->nextNode; har=har->nextNode->nextNode; } ptr2=tor; ptr1=tor->nextNode; tor->nextNode='\0'; har=ptr1; while(har!=NULL) { next=har->nextNode; har->nextNode=prev; prev=har; har=next; } head=prev; tor=str; while(tor->nextNode!=NULL) { next1=tor->nextNode; tor->nextNode=prev1; prev1=tor; tor=next1; } head1=prev1; fin=head1; while(fin->nextNode!=NULL) { fin=fin->nextNode; } fin->nextNode=ptr2; ptr2->nextNode=head; return head1; } }
Given LinkedList (where each node is integer), replace each element with the count of number of elements which are greater towards its right Input: 10->12->5->40->21->70->1->49->37->NULL Output: 6->5->5->3->3->0->2->0->0->NULL // here is the definition of SchNode public class SintNode { public int num; public SintNode nextNode; public SintNode(int num){ this.num = num; } } //Here is the Definition of SintNode for C Language struct SintNode { int num; struct SintNode * nextNode; }; NOTE: Do not use any printf or scanf statements while writing answers in C Language.
IN C
#include "common.h" #include "ExpCUtils.h" struct SintNode * func(struct SintNode * input) { struct SintNode *ptr1,*ptr2; int max, count=0; ptr1=input; while(ptr1!=NULL) { count=0; max=ptr1->num; ptr2=ptr1; while(ptr2!=NULL) { if(ptr2->num>max) { count++; } ptr2=ptr2->nextNode; } ptr1->num=count; ptr1=ptr1->nextNode; } return input; }