Microsoft interview questions (Collection)

Source: Internet
Author: User

1. In the sorting array, find the number of occurrences of a given number. For example, in [1, 2, 2, 2, 3], 2 appears three times.

# Include <stdio. h> extern int low = 0, high = 10, mid = 0; void find (int * a, int p) // locate P where {int I = 0, j = 0; while (low 

The algorithm complexity is O (logn ).

2. Reverse Order of a one-way linked list

(This practice from: http://www.baihowff.com/post/156.html)

How can this problem be solved? The simplest thing is to create a linked list... you can insert a head without stopping it... there must be two additional variables... but it's easy to understand... mongohowff sent today is obviously not this method... the method provided by javashowff can be implemented only by adding a Temporary Variable p... how can this problem be achieved?

Let me briefly talk about the algorithm... in fact, it is to point p to head-> next first, then assign head-> next to NULL, and then execute the loop while (p! = NULL) Switch head and p-> next and head and p... in fact, it is to store p to the next linked list element .. and then add... this algorithm is actually the same as using two ideas .. but it is very clever to write... let's first provide the complete program...

 

# Include <iostream> using namespace std; struct Node {Node * next; int data ;}; typedef Node * pNode; pNode Reverse (pNode head); void PrintList (pNode head ); int main (int argc, char * argv []) {// initialize a single-chain table head starting with 012345. The last one is named last pNode head = new Node; head-> data = 0; pNode a1 = new Node; a1-> data = 1; head-> next = a1; pNode a2 = new Node; a2-> data = 2; a1-> next = a2; pNode a3 = new Node; a3-> data = 3; a2-> next = a3; pN Ode a4 = new Node; a4-> data = 4; a3-> next = a4; pNode last = new Node; last-> data = 5; a4-> next = last; last-> next = NULL; cout <"before the chain table flip:"; PrintList (head); head = Reverse (head); cout <"after the chain table flip :"; printList (head); return 0;} pNode Reverse (pNode head) {// prevent incoming empty linked list if (head = NULL) return NULL; // pre-processing pNode p = new Node; p = head-> next; head-> next = NULL; // before and after the switch .. use p to indicate that the headers are not submitted .. head reversely stores while (p! = NULL) {swap (p-> next, head); // system function swap (head, p);} // prevent memory leakage delete p; p = NULL; // implement the chained operation return head;} void PrintList (pNode p) {while (NULL! = P) {cout <p-> data; p = p-> next;} cout <endl ;}

3. Write a regular expression to extract the link address from a string. For example
"The IT interview questions Blog contains many <a href = http://hi.baidu.com/mianshiti/blog/category/microsoft interview questions>
Microsoft interview questions </a>"
The address to be extracted is "http://hi.baidu.com/mianshiti/blog/category/microsoft Interview Questions"
Use the linux awk method:

Awk-F' [<>] ''{print $2} 'file name | grep 'HTTP .*'

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.