zoukankan      html  css  js  c++  java
  • 第三十次发博不知道用什么标题好

      1 #include<stdio.h>
      2 #include<stdlib>
      3 typedef struct node{
      4     int data;
      5     struct node *next;
      6 }Slist;
      7 Slist* Creatlist(Slist *L,int a[],int n)            //头插 
      8 {
      9     Slist *s;
     10     int i;
     11     L=(Slist*)malloc(sizeof(Slist));
     12     L->next=NULL;
     13     for(i=0;i<n;i++)
     14     {    
     15         s=(Slist*)malloc(sizeof(Slist));
     16         s->data=a[i];
     17         s->next=L->next;
     18         L->next=s;
     19     }
     20     return L;
     21 }
     22 
     23 Slist * Creat1(Slist *L,int a[],int n)            //尾插 
     24 {
     25     Slist *s;
     26     int i;
     27     L=(Slist*)malloc(sizeof(Slist));
     28     for(i=0;i<n;i++)
     29     {
     30         s=(Slist*)malloc(sizeof(Slist));
     31         s->data=a[i];
     32         L->next=s;
     33         L=s;
     34     }
     35     return L;
     36 }
     37 void Insert(Slist *L,int x,int i)            //指定位置插入 
     38 {
     39     Slist *s,*p=L;
     40     int j=0;
     41     while(p!=NULL&&j<i-1)
     42     {
     43         j++;
     44         p=p->next;
     45     }
     46         s=(Slist*)malloc(sizeof(Slist));
     47         s->data=x;
     48         s->next=p->next;
     49         p->next=s;
     50     }
     51  } 
     52 
     53 int Lenth(Slist*L)                            //长度 
     54 {
     55     int n;
     56     while(L->next!=NULL)
     57     {
     58         n++;
     59         L=L->next;
     60     }
     61      return n;
     62 }
     63 
     64 int Delet(Slist *L,int i)                //删除指定位置元素 
     65 {
     66     int j;
     67     Slist *p;
     68     while(L!=NULL&&j<i)
     69     {
     70         j++;
     71         L=L->next;
     72     }
     73     if(L==NULL)
     74     {
     75         return -1;
     76     }
     77     else
     78     {
     79         p=L->next;
     80         L->next=p->next;
     81         free(p); 
     82     }
     83     return 1;
     84  } 
     85  
     86 int Findlocation(Slist *L,int x,int *s)    //与x一样的值有几个 
     87 {
     88     int i,j;
     89     Slist *p=L;
     90     while(p->next!=NULL)
     91     {
     92         p=p->next;
     93         i++;
     94     }
     95     if(p->data==x)
     96     {
     97         *s=i;
     98         s++;
     99         j++;
    100     }
    101     return j;    
    102 }
    103 
    104 void Destorylist(Slist *L)                //销毁链表 
    105 {
    106     Slist *pre=L,*p=L->next;
    107     while(p!=NULL)
    108     {
    109         free(pre);
    110         pre=p;
    111         p=pre->next;
    112     }
    113     free(pre);
    114 }
    115 
    116 void Printlist(Slist *L)                //输出链表 
    117 
    118 {
    119     Slist *p=L->next;
    120     while(p!==NULL)
    121     {
    122         scanf("%d",p->data);
    123         p=p->next;
    124     }
    125                 

    又下了一天的雨

  • 相关阅读:
    python之连接oracle数据库
    从一副牌中随机抽一张牌
    判断一个点是否在圆内
    判断每个月有多少天
    猜数字游戏
    求一元二次方程的2个跟
    Servlet细节处理
    Servlet
    Http协议
    Struts2(2)
  • 原文地址:https://www.cnblogs.com/shi-yuan/p/10858859.html
Copyright © 2011-2022 走看看