<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                C [TOC] ### 題目描述 鏈表反轉: 給定一個常數K以及一個單鏈表L,請編寫程序將L中每K個結點反轉。例如:給定L為1→2→3→4→5→6,K為3,則輸出應該為3→2→1→6→5→4;如果K為4,則輸出應該為4→3→2→1→5→6,即最后不到K個元素不反轉。 輸入格式: 每個輸入包含1個測試用例。每個測試用例第1行給出第1個結點的地址、結點總個數正整數N(<=105)、以及正整數K(<=N),即要求反轉的子鏈結點的個數。結點的地址是5位非負整數,NULL地址用-1表示。 接下來有N行,每行格式為: Address Data Next 其中Address是結點地址,Data是該結點保存的整數數據,Next是下一結點的地址。 輸出格式: 對每個測試用例,順序輸出反轉后的鏈表,其上每個結點占一行,格式與輸入相同。 輸入樣例: 00100 6 4 00000 4 99999 00100 1 12309 68237 6 -1 33218 3 00000 99999 5 68237 12309 2 33218 輸出樣例: 00000 4 33218 33218 3 12309 12309 2 00100 00100 1 99999 99999 5 68237 68237 6 -1 ### 分析(偽代碼和知識點) ### 代碼 ``` #include<stdio.h> int main() { int head=0, n=0, v=0; scanf("%d%d%d", &head, &n, &v); int address=0, data=0, next=0, prior=0, ppp=0; int node[100000][3]={0};//0-prior 1-Data 2-Next for(int i=0; i<n; i++) { scanf("%d%d%d", &address, &data, &next); node[address][1]=data; node[address][2]=next; } next=head;//修補前指針 prior=head; for(int i=0; i<n; i++) { node[next][0]=prior; prior=next; next=node[next][2]; while(next<0) { n=i+1; break; } } ppp=next;//node[next][0]=prior; prior=-1; next=head; if(v<=1) v=n+1; for(int i=0; i<n;) { next=head; if(i+v <= n) { for(int j=i; j<i+v; j++) { if(j==i) next=head; else next=node[next][2]; } head=node[next][2]; for(int j=i; j<i+v; j++) { if(j) printf(" %05d\n", next); printf("%05d %d", next, node[next][1]); next=node[next][0]; } } else { for(int j=i; j<n; j++) { if(j) printf(" %05d\n", next); printf("%05d %d", next, node[next][1]); next=node[next][2]; } } i+=v; } printf(" %d", ppp); return 0; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看