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 位置是不变的。

  • 相关阅读:
    JChartFree创建饼形图
    JFreeChart设置点的颜色
    JChartFree使用散点图
    JChartFree常用数据集
    博客园安家了
    在Android中什么是异步执行;
    XmlPullParserException
    构造器的执行顺序
    Sqlite之contentProvider
    使用java获取歌曲的属性
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2414327.html
Copyright © 2011-2022 走看看