zoukankan      html  css  js  c++  java
  • 微软面试题:反序一个单向链表

    反序一个单向链表

    class Node {
    Node* next;
    }
    
    // Return the new start after reversion. 
    Node* ReverseList (Node* start) {  
    }
    #include <stdio.h> 
    
    typedef struct snode{ 
    char data; 
    struct snode *next;}node; 
    
    node *reserve(node *head){ 
    node *p,*q,*r; 
    p=head; 
    q=p->next; 
    while(q!=null){ 
    r=q->next; 
    q->next=p; 
    p=q; 
    q=r;} 
    head->next=null; 
    
    head=p; 
    
    return head; 
    
    } 
    

    这个题目有变种:
    对链表中部分节点进行反转操作,这些节点相隔k个:
    0->1->2->3->4->5->6->7->8->9
    k=2
    8->1->6->3->4->5->2->7->0->9
    注意1 3 5 7 9 位置是不变的。

  • 相关阅读:
    列表去重
    URL和URI的不同
    functional program language
    thinkphp5_笔记二
    关于《提问智慧》的笔记
    实习记录_2
    关于用户表的设计
    30秒运行超时的错误(Maximum execution time of 30 seconds exceeded)
    thinkphp5_笔记一
    Jquary 和Ajax实现简单的异步请求
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2414327.html
Copyright © 2011-2022 走看看