Hangzhou Rui Qi software face test

Source: Internet
Author: User

Recently participated in an interview, first introduced the company is to do software development, I am not very good at the algorithm, the results were abused crying. The following summary of the interview topic, I hope that the same problems can be referred to.
Question 1: We all know that Java is object-oriented, and I would like to ask the parent class of all classes in Java and the methods they have.

This question must be everyone, but very few people can all say the method of the parent class. Here's the answer:

A: The parent class of all classes is the object class. You can override its methods in the object subclass. The specific methods are listed below:

1:clone () method, which implements the creation of 1 objects of the same type.

2:equals ()/hashcode (): Note that these 2 methods must be overridden at the same time.

3:.finalize (). Recycle garbage to call this method.

4:tostring (). Returns the string of an object, which is generally overridden.

5:getclass (). Returns the class information for the object.

6:wait ().

7:notify ().

Other detailed usage and introduction reference: Http://www.blogjava.net/jiafang83/archive/2008/12/05/244510.html
Question 2: One-way linked list How to determine whether there is a ring.

This topic I learn the data structure at all did not practice, the class when the teacher also just mentioned, not very detailed explanation, interview when the head is covered. Hey...

Give the answer:

Method One: Use P, q Two pointers, p always go forward, but Q each time start from the beginning, for each node, see p Walk number of steps and Q. As shown in the figure, when p from 6 to 3 o'clock, with 6 steps, this time if the Q from head, then only two steps to 3, thus the number of steps, there are contradictions, there is a ring.

Method Two: Use P, q two pointers, p each step forward, Q each step forward two steps, if at some time p = = Q, there is a ring.

#include <stdio.h> #include <stdlib.h> #define LEN 8 typedef struct NODE* node_t;  
    struct node{char Val;  
struct node *next;  

};
Method 1 int Has_loop (struct node *head);

Method 2 int Has_loop2 (node_t head);
    int main () {node_t* arr = (node_t*) malloc (sizeof (struct node) *len);
    Arr[0] = (node_t) malloc (sizeof (struct node));
    int i;
        for (i = 1; i < LEN; i++) {Arr[i] = (node_t) malloc (sizeof (struct node));
    Arr[i-1]->next = Arr[i];

    } arr[len-1]->next = NULL;
    You can add a loop here to test//arr[6]->next = arr[0];
    if (Has_loop (arr[0])) printf ("Method1:has loop.\n");

    else printf ("Method1:has no loop.\n");
    if (HAS_LOOP2 (arr[0])) printf ("Method2:has loop.\n");

    else printf ("Method2:has no loop.\n");
return 0; }//if two pointer are equal, but they don ' t have the same steps, then has a loop int has_loop (node_t head) {nod e_t Cur1 = head;  
    int pos1 = 0;  
        while (CUR1) {node_t cur2 = head;  
        int pos2 = 0;  
        POS1 + +;  
            while (CUR2) {pos2 + +;  
                if (cur2 = = Cur1) {if (pos1 = = Pos2) break;
            else return 1;  
        } CUR2 = cur2->next;  
    } CUR1 = cur1->next;  
return 0; }//using Step1 and Step2 here//if exists a loop, then the pointer which use STEP2 would catch up with the pointer whic
    H uses Step1 int has_loop2 (node_t head) {node_t p = head;
    node_t q = head;
        while (P!= null && q!= NULL) {/* p = p->next;
        if (q->next!= NULL) q = q->next->next;
            if (p = = q) return 1;
        * *//correct it on 17/11/2012 p = p->next;
        Q = q->next;
        if (q!= NULL) q = q->next; if (P!= NULL && p = q) return 1;
return 0; }

3:java a single case pattern.
This peacetime practice is very few, some times have not heard the pattern design at all, because the ordinary concrete code encounters relatively few, be regarded as study.
This everyone Baidu will know, many online, design patterns have a common 23 kinds, single case mode needs to implement their own code a hungry man-style and lazy implementation (interview when I asked to write code on the scene). I can't write it.

The difference between pointers and references in 4.c++

Detailed See this blog: Others analysis, write more detailed http://blog.csdn.net/listening_music/article/details/6921608

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.