zoukankan      html  css  js  c++  java
  • 链表反转

    #include <iostream>
    using namespace std;
    typedef struct ListNode
    {
     int value;
     ListNode *next;

    }ListNode;
     ListNode *Reverse (ListNode *head)
    {
      ListNode *pnext;         
      ListNode *pre;        
      ListNode *pcur;        
     if(head->next==NULL)
      return head;
     pre = NULL;            
     pcur = head->next;             
     pnext = pcur->next;
     while(pnext!= NULL)
     {
      pcur->next = pre;
      pre = pcur;
      pcur = pnext;
      pnext = pcur->next;
     }
     pcur->next = pre;
     head->next = pcur;
     return head;
    }

    void traverse_link(ListNode *pHead)
    {
     if(pHead==NULL)
      return;
     ListNode *p = pHead->next;
     while(p!=NULL)
     {
      printf("%d ",p->value);
      p=p->next;
     }
     printf(" ");
    }

    void create_link(ListNode *pHead)
    {
     ListNode *pre;
     pHead->next = NULL;
     pre = pHead;
     for (int i =0;i<7;i++)
     {
      ListNode *ptemp = new ListNode;
      ptemp->value = i;
      ptemp->next=NULL;
      pre->next = ptemp;
      pre = ptemp;

     }
    }

    int main()
    {
     ListNode *head = new ListNode;;
     create_link(head);
     traverse_link(head);
     Reverse(head);
     traverse_link(head);
     system("pause");
     return 0;
    }

  • 相关阅读:
    TCP四种定时器--学习笔记
    Python魔术师--self
    python的socket里 gethostbyname 与 gethostbyname_ex 的区别
    用python查看URL编码的中文
    基于linux 的2048
    用灵活的指针访问类私有变量
    ie8无法拉伸背景图
    图片的onerror 事件解析
    stream.js
    Promise
  • 原文地址:https://www.cnblogs.com/cheng07045406/p/3286323.html
Copyright © 2011-2022 走看看