Huawei machine exam questions

Source: Internet
Author: User

Reverse placement of a single-chain table

Void sor (node ** head) {If (! Head) return; // node * cur = * head; If (! Cur |! Cur-> next) return; // The list is empty, or there is only one node // cur // | // v // node1-> node2-> node3->... node5node * Prev = NULL; while (cur & cur-> next) {// save curnode * temp = cur; // cur, temp // | // v // node1-> node2-> node3->... node5 // move a cur = cur-> next; // temp cur // | // v // node1-> node2-> node3->... node5 // The next pointer of the temporary node points to the previous prevtemp-> next = Prev; // temp cur // | // v // node1 node2-> node3->... node5 // | // v // Prev (null) // give the pointer value of the temporary node to prevprev = temp; // temp, prev cur // | // v // node1 node2-> node3->... node5 // | // v // (null)} cur-> next = Prev; * head = cur ;}

Integer to String Conversion

Void change (INT number, char s []) {bool is_minus = (number <0); number = is_minus? Number *-1: Number; char * x = s; do {* x ++ = Number % 10 + '0'; number/= 10 ;}while (number ); if (is_minus) * x ++ = '-'; // Terminator * x = '\ 0'; // invert int Len = strlen (s ); for (INT I = 0; I <(len-1)/2; I ++) {char c = s [I]; s [I] = s [len-i-1]; s [len-i-1] = C;} return ;}

Maximum text return

Void Huiwen (char input [], int Len, char output []) {for (INT I = Len; I> = 1; I --) {for (Int J = 0; j <= len-I; j ++) {// judge input [j... (len-i-1-j)] whether this paragraph is a text back // use the classic retrieval algorithm int head = J; int tail = J + I-1; while (Head <tail & input [head ++] = input [tail --]); // subscripts are staggered // If (head> = tail) {// memcpy (output, input + J, I); Return ;}}} is returned after I is copied from J ;}}}}

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.