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

    怎么感觉好几天没打卡,手都生疏了.....

      1 #include<stdio.h>
      2 #include<stdlib.h>
      3 typedef struct node{
      4     int data;
      5     struct node *next;
      6 }slist;
      7 
      8 slist * creatfront(slist *L,int a[],int n)
      9 {    int i;
     10     slist *s;
     11     for(i=0;i<n;i++)
     12     {
     13         s=(slist*)malloc(sizeof(slist));
     14         s->data=a[i];
     15         s->next=L->next;
     16         L->next=s;
     17     }
     18     return L;
     19 }
     20 
     21 void creatlater(slist *L,int a[],int n)
     22 {
     23     slist *p=L,*s;
     24     int i;
     25     for(i=0;i<n;i++)
     26     {
     27         s=(slist*)malloc(sizeof(slist));
     28         s->data=a[i];
     29         s->next=p->next;
     30         p->next=s;
     31         p=s;    
     32     }
     33 }
     34 
     35 void insert(slist *L,int i,int x)
     36 {
     37     int j=0;
     38     slist *p=L,*s;
     39     while(p!=NULL&&j<i-1)
     40     {
     41         j++;
     42         p=p->next;
     43     }
     44     s=(slist*)malloc(sizeof(slist));
     45     s->data=x;
     46     s->next=p->next;
     47     p->next=s; 
     48 }
     49 
     50 int  delet(slist *L,int x,int i)
     51 {
     52     int j=0;
     53     slist *p;
     54     while(L!=NULL&&j<i)
     55     {
     56         j++;
     57         L=L->next;
     58     }
     59     if(L==NULL)
     60     return i;
     61     else
     62     {
     63         p=L->next;
     64         L->next=p->next;
     65         free(p);
     66     }
     67         return 1;        
     68 }
     69 
     70 int length(slist *L)
     71 {
     72     int n;
     73     while(L!=NULL)
     74     {
     75         n++;
     76         L=L->next;
     77     }
     78         return n;
     79 }
     80 
     81 void destroy(slist *L)
     82 {
     83     slist *pre=L,*p=L->next;
     84     while(p!=NULL)
     85     {
     86         free(pre);
     87         pre=p;
     88         p=p->next;
     89     }
     90         free(pre);
     91 }
     92 
     93 void print(slist *L)
     94 {
     95     slist *p=L;
     96     while(p!=NULL)
     97     {
     98         scanf("%d",p->data);
     99         p=p->next;
    100     }
    101 }
    102 
    103 int findlocation(slist *L,int x,int *e)
    104 {
    105     int i,j;
    106     slist *p=L;
    107     while(p->next!=NULL)
    108     {
    109         p=p->next;
    110         i++;    
    111     }
    112     if(p->data==x)
    113     {
    114         *e=i;
    115         e++;
    116         j++;
    117     }
    118         return j;
    119         
    120 }
  • 相关阅读:
    网站首页蒙灰CSS样式
    MATLAB数值计算编程题
    通过P/Invoke控制继电器
    Java实习生入职测试
    navicat for mongodb12破解
    用svg绘制圣诞帽
    Excel条件格式
    10道算法题
    从事软件开发工作10年后的总结
    ASP.NET Core MVC+EF Core从开发到部署
  • 原文地址:https://www.cnblogs.com/shi-yuan/p/10941497.html
Copyright © 2011-2022 走看看