⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-c++ 笔试、面试题目大汇总.htm

📁 面试题 希望对大家有所帮助 成功走向程序员之路
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            <DIV><FONT 
            size=2><STRONG>39.文件中有一组整数,要求排序后输出到另一个文件中</STRONG><BR>答案:</FONT></DIV>
            <DIV><FONT size=2>#i nclude&lt;iostream&gt;</FONT></DIV>
            <DIV><FONT size=2>#i nclude&lt;fstream&gt;</FONT></DIV>
            <DIV><FONT size=2>using namespace std;</FONT></DIV>
            <DIV><BR><FONT size=2>void Order(vector&lt;int&gt;&amp; data) 
            //bubble sort<BR>{<BR>int count = data.size() ;<BR>int tag = false ; 
            // 设置是否需要继续冒泡的标志位<BR>for ( int i = 0 ; i &lt; count ; 
            i++)<BR>{<BR>for ( int j = 0 ; j &lt; count - i - 1 ; 
            j++)<BR>{<BR>if ( data[j] &gt; data[j+1])<BR>{<BR>tag = true 
            ;<BR>int temp = data[j] ;<BR>data[j] = data[j+1] ;<BR>data[j+1] = 
            temp ;<BR>}<BR>}<BR>if ( !tag )<BR>break ;<BR>}<BR>}</FONT></DIV>
            <DIV><BR><FONT size=2>void main( void 
            )<BR>{<BR>vector&lt;int&gt;data;<BR>ifstream 
            in("c:\\data.txt");<BR>if ( !in)<BR>{<BR>cout&lt;&lt;"file 
            error!";<BR>exit(1);<BR>}<BR>int temp;<BR>while 
            (!in.eof())<BR>{<BR>in&gt;&gt;temp;<BR>data.push_back(temp);<BR>}<BR>in.close(); 
            //关闭输入文件流<BR>Order(data);<BR>ofstream out("c:\\result.txt");<BR>if ( 
            !out)<BR>{<BR>cout&lt;&lt;"file error!";<BR>exit(1);<BR>}<BR>for ( i 
            = 0 ; i &lt; data.size() ; i++)<BR>out&lt;&lt;data[i]&lt;&lt;" 
            ";<BR>out.close(); //关闭输出文件流<BR>}</FONT></DIV>
            <DIV><FONT size=2></FONT>&nbsp;</DIV>
            <DIV><FONT size=2><STRONG>40. 链表题:一个链表的结点结构<BR>struct 
            Node<BR>{<BR>int data ;<BR>Node *next ;<BR>};<BR>typedef struct Node 
            Node ;</STRONG></FONT></DIV>
            <DIV><BR><STRONG><FONT size=2>(1)已知链表的头结点head,写一个函数把这个链表逆序 ( 
            Intel)</FONT></STRONG></DIV>
            <DIV><FONT size=2>Node * ReverseList(Node *head) //链表逆序<BR>{<BR>if ( 
            head == NULL || head-&gt;next == NULL )<BR>return head;<BR>Node *p1 
            = head ;<BR>Node *p2 = p1-&gt;next ;<BR>Node *p3 = p2-&gt;next 
            ;<BR>p1-&gt;next = NULL ;<BR>while ( p3 != NULL 
            )<BR>{<BR>p2-&gt;next = p1 ;<BR>p1 = p2 ;<BR>p2 = p3 ;<BR>p3 = 
            p3-&gt;next ;<BR>}<BR>p2-&gt;next = p1 ;<BR>head = p2 ;<BR>return 
            head ;<BR>}<BR><STRONG>(2)已知两个链表head1 和head2 
            各自有序,请把它们合并成一个链表依然有序。(保留所有结点,即便大小相同)</STRONG><BR>Node * Merge(Node 
            *head1 , Node *head2)<BR>{<BR>if ( head1 == NULL)<BR>return head2 
            ;<BR>if ( head2 == NULL)<BR>return head1 ;<BR>Node *head = NULL 
            ;<BR>Node *p1 = NULL;<BR>Node *p2 = NULL;<BR>if ( head1-&gt;data 
            &lt; head2-&gt;data )<BR>{<BR>head = head1 ;<BR>p1 = 
            head1-&gt;next;<BR>p2 = head2 ;<BR>}<BR>else<BR>{<BR>head = head2 
            ;<BR>p2 = head2-&gt;next ;<BR>p1 = head1 ;<BR>}<BR>Node *pcurrent = 
            head ;<BR>while ( p1 != NULL &amp;&amp; p2 != NULL)<BR>{<BR>if ( 
            p1-&gt;data &lt;= p2-&gt;data )<BR>{<BR>pcurrent-&gt;next = p1 
            ;<BR>pcurrent = p1 ;<BR>p1 = p1-&gt;next 
            ;<BR>}<BR>else<BR>{<BR>pcurrent-&gt;next = p2 ;<BR>pcurrent = p2 
            ;<BR>p2 = p2-&gt;next ;<BR>}<BR>}<BR>if ( p1 != NULL 
            )<BR>pcurrent-&gt;next = p1 ;<BR>if ( p2 != NULL 
            )<BR>pcurrent-&gt;next = p2 ;<BR>return head ;<BR>}<BR></FONT><FONT 
            size=2><STRONG>(3)已知两个链表head1 和head2 
            各自有序,请把它们合并成一个链表依然有序,这次要求用递归方法进行。 (Autodesk)<BR></STRONG>答案:<BR>Node 
            * MergeRecursive(Node *head1 , Node *head2)<BR>{<BR>if ( head1 == 
            NULL )<BR>return head2 ;<BR>if ( head2 == NULL)<BR>return head1 
            ;<BR>Node *head = NULL ;<BR>if ( head1-&gt;data &lt; head2-&gt;data 
            )<BR>{<BR>head = head1 ;<BR>head-&gt;next = 
            MergeRecursive(head1-&gt;next,head2);<BR>}<BR>else<BR>{<BR>head = 
            head2 ;<BR>head-&gt;next = 
            MergeRecursive(head1,head2-&gt;next);<BR>}<BR>return head 
            ;<BR>}</FONT></DIV>
            <DIV><FONT size=2><STRONG>41. 分析一下这段程序的输出 
            (Autodesk)</STRONG><BR>class 
            B<BR>{<BR>public:<BR>B()<BR>{<BR>cout&lt;&lt;"default 
            constructor"&lt;&lt;endl;<BR>}<BR>~B()<BR>{<BR>cout&lt;&lt;"destructed"&lt;&lt;endl;<BR>}<BR>B(int 
            i):data(i)&nbsp;&nbsp;&nbsp; //B(int) works as a converter ( int 
            -&gt; instance of &nbsp;B)<BR>{<BR>cout&lt;&lt;"constructed by 
            parameter " &lt;&lt; data &lt;&lt;endl;<BR>}<BR>private:<BR>int 
            data;<BR>};</FONT></DIV>
            <DIV><BR><FONT size=2>B Play( B b) <BR>{<BR>return b 
            ;<BR>}</FONT></DIV>
            <DIV><FONT 
            size=2>(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            results:<BR>int main(int argc, char* 
            argv[])&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructed by parameter 
            5<BR>{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            destructed&nbsp; B(5)<STRONG>形参</STRONG>析构<BR>B t1 = Play(5); B t2 = 
            Play(t1);&nbsp;&nbsp;   destructed&nbsp; t1形参析构<BR>return 
            0;               destructed&nbsp; t2 <STRONG><FONT 
            color=#ff0000>注意顺序!</FONT></STRONG><BR>}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;destructed&nbsp; 
            t1</FONT></DIV>
            <DIV><FONT 
            size=2>(2)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;results:<BR>int 
            main(int argc, char* 
            argv[])&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;constructed by parameter 
            5<BR>{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            destructed&nbsp; B(5)<STRONG>形参</STRONG>析构<BR>B t1 = Play(5); B t2 = 
            Play(10);&nbsp;&nbsp;   constructed by parameter 10<BR>return 
            0;               destructed&nbsp; 
            B(10)<STRONG>形参</STRONG>析构<BR>}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            destructed&nbsp; t2 <FONT 
            color=#ff0000><STRONG>注意顺序!</STRONG></FONT></FONT></DIV>
            <DIV><FONT color=#ff0000><FONT color=#000000 
            size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            destructed&nbsp; t1</FONT></FONT></DIV>
            <DIV><FONT size=2><STRONG>42. 写一个函数找出一个整数数组中,第二大的数 
            (microsoft)<BR></STRONG>答案:<BR>const int MINNUMBER = -32767 ;<BR>int 
            find_sec_max( int data[] , int count)<BR>{<BR>int maxnumber = 
            data[0] ;<BR>int sec_max = MINNUMBER ;<BR>for ( int i = 1 ; i &lt; 
            count ; i++)<BR>{<BR>if ( data[i] &gt; maxnumber )<BR>{<BR>sec_max = 
            maxnumber ;<BR>maxnumber = data[i] ;<BR>}<BR>else<BR>{<BR>if ( 
            data[i] &gt; sec_max )<BR>sec_max = data[i] ;<BR>}<BR>}<BR>return 
            sec_max ;<BR>}</FONT></DIV>
            <DIV><STRONG><FONT size=2>43. 
            写一个在一个字符串(n)中寻找一个子串(m)第一个位置的函数。</FONT></STRONG></DIV>
            <DIV><FONT size=2>KMP算法效率最好,时间复杂度是O(n+m)。</FONT></DIV>
            <DIV><FONT size=2><STRONG>44. 多重继承的内存分配问题:<BR>&nbsp;&nbsp; 比如有class 
            A : public class B, public class C {}<BR>&nbsp;&nbsp; 
            那么A的内存结构大致是怎么样的?</STRONG><BR><BR>这个是compiler-dependent的, 
            不同的实现其细节可能不同。<BR>如果不考虑有虚函数、虚继承的话就相当简单;否则的话,相当复杂。<BR>可以参考《深入探索C++对象模型》,或者:<BR><A 
            href="http://blog.csdn.net/wfwd/archive/2006/05/30/763797.aspx">http://blog.csdn.net/wfwd/archive/2006/05/30/763797.aspx</A></FONT></DIV>
            <DIV><FONT size=2><STRONG>45. 
            如何判断一个单链表是有环的?(注意不能用标志位,最多只能用两个额外指针)<BR></STRONG><BR>&nbsp;&nbsp; 
            struct node { char val; node* next;}<BR><BR>&nbsp;&nbsp;&nbsp;bool 
            check(const node* head) {} //return&nbsp;false : 无环;true: 
            有环</FONT></DIV>
            <DIV><FONT 
            size=2>一种O(n)的办法就是(搞两个指针,一个每次递增一步,一个每次递增两步,如果有环的话两者必然重合,反之亦然):<BR>bool 
            check(const node* head)<BR>{<BR>&nbsp;&nbsp;&nbsp; 
            if(head==NULL)&nbsp; return false;<BR>&nbsp;&nbsp;&nbsp; node 
            *low=head, *fast=head-&gt;next;<BR>&nbsp;&nbsp;&nbsp; 
            while(fast!=NULL &amp;&amp; 
            fast-&gt;next!=NULL)<BR>&nbsp;&nbsp;&nbsp; 
            {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            low=low-&gt;next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            fast=fast-&gt;next-&gt;next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            if(low==fast) return true;<BR>&nbsp;&nbsp;&nbsp; 
            }<BR>&nbsp;&nbsp;&nbsp; return 
            false;<BR>}</FONT></DIV></SPAN></SPAN></SPAN></SPAN></DIV><BR><BR>
            <SCRIPT type=text/javascript><!--
google_ad_client = "pub-2976487794163546";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2006-11-22: xia
google_ad_channel = "3545415502";
//--></SCRIPT>

            <SCRIPT src="C-C++ 笔试、面试题目大汇总.files/show_ads.js" 
            type=text/javascript>
</SCRIPT>

            <TABLE style="CLEAR: both" cellSpacing=0 cellPadding=0 
              width="97%"><TBODY>
              <TR>
                <TD align=right>
                  <TABLE>
                    <TBODY>
                    <TR>
                      <TD>阅读:<SPAN id=news_hits></SPAN> 次<BR>录入:<SPAN 
                        id=MemberNameLabel><A 
                        href="http://www.yoent.com/memberProfile.aspx?id=2" 
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -