AceTheInterview
Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answer »

  1. Submitted By: Kiranmai — April 16, 2009
    -1 votes
      + -

    1) Take each input from the file. and for the first five items put it in a linked list. head pointer points to the start of the list and last pointer points to the fifth element.
    2) when iteration starts from the 6th element, compare the age of the ith element to the age pointed by the “last” pointer. if it is greater, free the “last” pointer and update it to the previous
    3) try to insert the ith node to the existing 4 element linked list and update the “last” pointer accordingly so that it points to the last element of the list.

    Eg:

    //get the input from the file..
    int temp;
    int N = getinputfromFile ( ) //some file operation to read inputs from file.
    struct list *ageArr = NULL;
    strcut list *head = NULL;
    struct list *last = NULL;
    struct list *tmpLast = NULL;
    strcut list *tmpArr = NULL;

    for ( i= 1; iage = getInputFromFile();
    tmpArr->index= i;
    tmpArr->next = NULL;
    if (ageArr == NULL ) {
    head = ageArr;
    ageArr = tmpArr;
    ageArr->prev = NULL;
    else {
    ageArr = head;
    while (tmpArr->age age ) {
    if(ageArr->next != NULL)
    ageArr = ageArr->next;
    else break;
    }
    ageArr->next =tmpArr;
    ageArr->next->prev = ageArr
    ageArr = ageArr->next;
    }
    }
    last = ageArr;

    for (i=6; i last->age) {
    last= last->prev;
    last->next->prev = NULL;
    free(last->next);
    last->next = NULL;
    tmpArr= malloc (sizeof(struct list));
    tmpArr->age = temp;
    tmpArr->index= i;
    tmpArr->next = NULL;
    while(last->age prev;
    }
    if (last == NULL) {
    tmpArr->next = head;
    tmpArr->prev= NULL;
    head->prev = tmpArr;
    head = tmpArr;
    }
    else {
    tmpArr->next = last->next;
    last->next = tmpArr;
    tmpArr->next->prev = tmpArr;
    tmpArr->prev = last;
    }
    if (tmpLast == NULL) last = tmpArr;
    else last = tmpLast;
    }
    }

    }

  2. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.