AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | 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

Answers »

  1. Submitted By: albela — October 6, 2006
    +1 votes
      + -

    Use Mergesort.

  2. Submitted By: dambo — October 6, 2006
    not yet rated
      + -

    node * insert(node * to_insert,node * sorted) {
    if (to_insert->value<sorted->value){
    to_insert->next=sorted;
    return to_insert;
    }
    node * temp = sorted;
    while((temp->next!=null) && (to_insert->value>=temp->next->value)
    temp=temp->next;
    if (temp->next==null) {
    temp->next=to_insert;
    return sorted;
    }
    to_insert->next=temp->next;
    temp->next=to_insert;
    return sorted;
    }

    node * sort(node * list) {
    node * sorted=list;
    list=list->next;
    sorted->next=null;
    while (list!=null) {
    temp=list;
    list=list->next;
    temp->next=null;
    sorted=insert(temp,sorted);
    }
    return sorted;
    }

  3. Submitted By: 1mahesh — October 6, 2006
    +2 votes
      + -

    sorting in descending order
    struct node{
    int value;
    node* NEXT;
    }
    Assume HEAD pointer denotes the first element in the linked list
    Sort()
    {
    node* first,second,temp;
    first=HEAD;
    while(first!=null)
    {
    second=first->NEXT;
    while(second!=null)
    {
    if(first->value<second->value)
    {
    temp=new node();
    temp->value=first->value;
    first->value=second->value;
    second->value=temp->value;
    delete temp;
    }
    second=second->NEXT;
    }
    first=first->NEXT;
    }
    }

  4. Submitted By: TimeHawk — October 6, 2006
    not yet rated
      + -

    Simple linked list in COBOL using relative record setup.

    Call me a bit ignorant of newer, memory saving logics, but here we go.
    With a one dimensional, multiple field table (rel #, link, data) i would read the used pointer which points to the first record.

    Do this in a PERFORM VARYING Table-Sub Rel-Key FROM
    1 BY 1 UNTIL Finished-Flag. And increment Link from 2 by 1 within PERFORM.

    Insert the first record into the table, follow the link so on…

    When done PERFORM, Re-Write records back into Link-List-File.

    This is assuming that you want the record based on primary acsending key and links going from:
    Rel - 1, Link - 2
    Rel - 2, Link - 3

    No matter how I look at it, it will take a big chunk of memory to acomplish this on a huge database.

  5. Submitted By: hkdua — October 6, 2006
    not yet rated
      + -

    void sort_list(NODEPTR *q)
    {
    NODEPTR r, s, t, u;

    s = NULL;

    while (s != (*q)->next)
    {
    r = t = *q;
    r = t->next;
    while (t != s)
    {
    if (t->info > r->info)
    {
    if (t == *q)
    {
    t->next = r->next;
    r->next = t;
    *q = r;
    u = r;
    }
    else
    {
    t->next = r->next;
    r->next = t;
    u->next = r;
    u = r;
    }
    }
    else
    {
    u = t;
    t = t->next;
    }

    r = t->next;
    if (r == s)
    s = t;
    }
    }
    }

  6. Submitted By: sharath — October 6, 2006
    -1 votes
      + -

    One of the easy was to sort is:

    sort_list(NODE **nPtr)
    {
    NODE *x,*y,*z;

    if ( *nPtr == NULL ) return;

    x = *nPtr;
    y = NULL;

    while( temp != NULL )
    {
    z = y;
    y = x;
    x = x->link;
    y = z->link;
    }

    *nPtr = y;
    }

  7. Submitted By: shanu_eternal — October 6, 2006
    +1 votes
      + -

    The merge sort algorithm

    merge(node *p,node *q)
    {

  8. Submitted By: shanu_eternal — October 6, 2006
    not yet rated
      + -

    The merge sort algorithm
    typedef struct node
    {
    int key;
    struct node *next;
    }node;

    node *head;
    node * merge(node *p,node *q)
    {
    node *temp;
    node *r;
    if(p->key < q->key)
    {
    temp=p;
    p=p->next;
    }
    else
    {
    temp=q;
    q=q->next;
    }
    r=temp;
    while(p&&q)
    {
    if(p->key<q->key)
    {
    r->next=p;
    r=r->next;
    p=p->next;
    }
    else
    {
    r->next=q;
    r=r->next;
    q=q->next;
    }
    if(p)
    r->next=p;
    if(q)
    r->next=q;
    }
    node * find(node *a)
    {
    node *p;
    node *r;
    p=a;
    r=a->next->next;
    while(r)
    {

    p=p->next;
    int merge_sort(node *a)
    {
    node *p;
    if(a && a->next)
    {
    p = find(a);
    merge_sort(a);
    merge_sort(p);
    merge(a,p);
    }
    return a;
    }

  9. Submitted By: shanu_eternal — October 6, 2006
    +3 votes
      + -

    The merge sort algorithm
    typedef struct node
    {
    int key;
    struct node *next;
    }node;

    node *head;
    node * merge(node *p,node *q)
    {
    node *temp;
    node *r;
    if(p->key < q->key)
    {
    temp=p;
    p=p->next;
    }
    else
    {
    temp=q;
    q=q->next;
    }
    r=temp;
    while(p&&q)
    {
    if(p->key<q->key)
    {
    r->next=p;
    r=r->next;
    p=p->next;
    }
    else
    {
    r->next=q;
    r=r->next;
    q=q->next;
    }
    if(p)
    r->next=p;
    if(q)
    r->next=q;
    }
    node * find(node *a)
    {
    node *p;
    node *r;
    p=a;
    r=a->next->next;
    while(r)
    {
    r=r->next;
    p=p->next;
    if(r)
    r=r->next;
    }
    r=p->next;
    p->next=null;
    return r;
    }
    int merge_sort(node *a)
    {
    node *p;
    if(a && a->next)
    {
    p = find(a);
    merge_sort(a);
    merge_sort(p);
    merge(a,p);
    }
    return a;
    }

  10. Submitted By: nsraja — October 6, 2006
    +0 votes
      + -

    void LBucketSort(PNODE phead)
    {
    PNODE pstep, pnode;
    int t;
    pnode = phead;
    while (pnode)
    {
    pstep = pnode->next;
    while (pstep)
    {
    if (pnode->d > pstep->d)
    {
    t = pnode->d;
    pnode->d = pstep->d;
    pstep->d = t;
    }
    pstep = pstep->next;
    }
    pnode = pnode->next;
    }
    }

  11. Submitted By: J1gs4w — June 2, 2008
    not yet rated
      + -

    @Sharath
    That algorithm is for REVERSING a linked list-not for sorting it.

  12. 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.