zoukankan      html  css  js  c++  java
  • 数据结构——A-Z的单链表

     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 
     4 typedef char Elemtype;
     5 
     6 typedef struct node
     7 {
     8     Elemtype data;
     9     struct node *next;
    10 }Lnode,*Linklist;
    11 
    12 void createHead(Linklist *L)
    13 {
    14     Linklist s;
    15     int i;
    16     printf("头插法:
    ");
    17     *L = (Linklist)malloc(sizeof(Lnode)); 
    18     (*L)->next = NULL;
    19 
    20     for(i=0;i<26;i++)
    21     {
    22         s = (Linklist)malloc(sizeof(Lnode));
    23         
    24         s->data = 65+i;
    25         s->next = (*L)->next;
    26         (*L)->next = s;
    27     }
    28 }
    29 void createRear(Linklist *L)
    30 {
    31     Linklist s,rear;
    32     int i;
    33     printf("尾插法:
    ");
    34 
    35     *L = (Linklist)malloc(sizeof(Lnode));
    36     rear = *L;
    37 
    38     for(i=0;i<26;i++)
    39     {
    40         s = (Linklist)malloc(sizeof(Lnode));
    41         s->data = 65+i;
    42         rear->next = s;
    43         rear = s;
    44     }
    45     rear->next = NULL;
    46 
    47 }
    48 void print(Linklist L)
    49 {
    50     Linklist p = L->next;
    51     while(p)
    52     {
    53         printf("%c ",p->data);
    54         p = p->next;
    55     }
    56     printf("
    ");
    57 }
    58 int main()
    59 {
    60     Linklist La,Lb;
    61     
    62     createHead(&La);
    63     print(La);
    64 
    65     createRear(&Lb);
    66     print(Lb);
    67 
    68     return 0;
    69 }
    View Code
  • 相关阅读:
    ASP.NET中JSON的序列化和反序列化
    Android:数据存储之SQLite
    转Android:简单联网获取网页代码
    Android:@id和@+id
    linux .run文件安装
    Mysql的Root密码忘记,查看或修改的解决方法(图文介绍)
    网页页面尺寸
    openstack
    br0
    virsh
  • 原文地址:https://www.cnblogs.com/biu-biu-biu-/p/6063412.html
Copyright © 2011-2022 走看看