zoukankan      html  css  js  c++  java
  • 链表基本操作

    1.创建链表

    2.插入节点

    node *intsert(node *head,int num)
    {
     node *p0,*p1,*p2;
     p1=head;
     p0=(node *)malloc(sizeof(node));
     p0->data=num;
     while(p0->data>p1->data&&p1->next!=NULL)
     {
      p2=p1;//将前节点存放起来
      p1=p1->next;
     }
     if(p0->data<=p1->data)
     {
      if(p1==head)
      {
       p0->next=p1;
       head=head;
      }
      else
      {
       p2->next=p0;
       p0->next=p1;
      }
     }
     else
     {
      p1->next=p0;
      p0->next=NULL;
     }
     return head;

    }

    3.链表排序

    node *sort(node *head)
    {
     node *p;
     int i,j,n,temp;
     p=head;
     n=length(head);//获取链表长度
     if(head==NULL||head->next=NULL)//判断链表是否为空
     {
      return head;
     }
     for(i=1;i<n;i++)
     {
      p=head;//将指针定位到链表头
      for(j=1;j<n-i;j++)//采用冒泡法进行排序
      {
       if(p->data>p->next->data)
       {
        temp=p->data;
        p->data=p->next->data;
        p->next->data=temp;
       }
       p=p->next;//每一次链表节点后移一位
      }
     }
     return head;
    }

  • 相关阅读:
    flare3d_plane
    flare3d_TextureFilter
    flare3d_animation
    flare3d黄色星球案例再次解读整理
    pureMVC(二)
    flare3d_ColladaLoader
    flare3d_clone
    四则运算
    15章
    带界面的四则运算
  • 原文地址:https://www.cnblogs.com/jife/p/3380024.html
Copyright © 2011-2022 走看看