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: johny1 — October 6, 2006
    +1 votes
      + -

    bool sortedinsert(node* head, int val)
    {
    node* curr = head;
    while(curr)
    {
    if(curr->next)
    {
    if(curr->next.val > val)
    node* newnode = new node(val);
    newnode->next = curr->next;
    curr->next = newnode;
    return 1;
    }
    }
    return -1;
    }

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

    my solution (C++):

    void insert(int val){
    Node* prev, *curr = pHead;
    while (!curr && curr->value <= val){
    prev = curr;
    curr = curr->next;
    }
    if (!curr){
    if (!pHead){
    Node* temp = new Node(val);
    temp->next = pHead;
    pHead = temp;
    }
    else pHead = new Node(val);
    }
    else {
    Node *temp = new Node(val);
    temp->next = curr;
    prev->next = temp;
    }
    }

  3. Submitted By: rdakka — October 6, 2006
    not yet rated
      + -

    void insert(node*& s, node* d, node* prev = 0)
    {
    if (s) {
    if (s->data > d->data) {
    d->next = s;
    if (prev) prev->next = d;
    return;
    }
    else insert(s->next, d, s);
    }
    else {
    ((prev) ? prev->next : s) = d;
    d->next = 0;
    }
    }

    insert(root, n1);
    insert(root, n2);

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

    void insert(Node **NodePtr, Node *NewNode)
    {
    while(*NodePtr != NULL && *NodePtr-> Value > Value)
    {
    NodePtr = &(*NodePtr->Next);
    }
    NewNode->Next = *NodePtr!=NULL?*NodePtr:NULL;
    *NodePtr = NewNode;
    }

  5. Submitted By: SP — September 25, 2007
    not yet rated
      + -

    struct node
    {
    int data;
    struct node * next;
    };

    void insert_order(struct node ** list, int val)
    {
    //construct a node out of value given
    struct node *newnode= getnode(); //return malloc(sizeof(struct node));
    newnode->data=val;
    newnode->next=null;

    //insert a node at proper position

    struct node *temp=list;
    if(temp==null){
    list=newnode;
    return;
    }
    struct node * prev=null;
    while(temp!=null && temp->data data )
    {
    prev=temp;
    temp=temp->next;
    }
    //insert new node netween prev and temp nodes
    prev->next=newnode;
    newnode->next=temp;
    return;
    }

  6. Submitted By: S P — September 25, 2007
    not yet rated
      + -

    correction at one line
    while(temp!=null && temp->data data )

    read it as
    while(temp!=null && temp->data data )

  7. Submitted By: Sneha — September 25, 2007
    not yet rated
      + -

    //structure of node
    struct node
    {
    int data;
    struct node * next;
    };

    void insert_order(struct node ** list, int val)
    {
    //construct a node out of value given
    struct node *newnode= getnode(); //return malloc(sizeof(struct node));
    newnode->data=val;
    newnode->next=null;

    //insert a node at proper position

    struct node *temp=list;
    if(temp==null){
    list=newnode;
    return;
    }
    struct node * prev=null;
    while(temp!=null && temp->data data )
    {
    prev=temp;
    temp=temp->next;
    }
    //insert new node netween prev and temp nodes
    prev->next=newnode;
    newnode->next=temp;
    return;
    }

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