zoukankan      html  css  js  c++  java
  • 尾插法链表拆分

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 /*
     4 尾插法链表拆分:1.建立空链表。2.插入节点。3.遍历并输出插入节点后的链表数据
     5 */
     6 typedef struct node
     7 {
     8     int data;
     9     struct node * next;
    10 }NODE;
    11 //建立空链表
    12 NODE * createList()
    13 {
    14     NODE * head = (NODE *)malloc(sizeof(NODE));
    15     head->next = NULL;
    16 
    17     return head;
    18 }
    19 //插入节点
    20 NODE * insertNode(NODE * pt,int nodeData)
    21 {
    22     NODE * cur = (NODE *)malloc(sizeof(NODE));
    23     cur->data = nodeData;
    24 
    25     pt->next = cur;
    26     cur->next = NULL;
    27     pt = cur;
    28 
    29     return pt;
    30 }
    31 //遍历并输出插入节点后的链表元素
    32 void traverList(NODE *head)
    33 {
    34     head = head->next;
    35     while(head)
    36     {
    37         printf("%d
    ",head->data);
    38         head = head->next;
    39     }
    40 }
    41 
    42 int main(void)
    43 {
    44     //建立空链表
    45     NODE * head = createList();
    46     //插入节点
    47     NODE * pt = head;//定义pt保存尾节点的地址
    48     for(int i=0;i<50;i++)
    49     {
    50         pt = insertNode(pt,i);
    51     }
    52     //遍历并输出插入节点后的链表元素
    53     traverList(head);
    54     return 0;
    55 }
  • 相关阅读:
    webuploader与django进行断点续传
    mac os 关于rar后缀压缩文件解压
    django forms组件
    迭代器
    函数的进阶
    初识函数
    ⽂件操作
    set集合,深浅拷⻉以及部分知识点补充
    再谈编码
    基本数据类型(dict)
  • 原文地址:https://www.cnblogs.com/wangchaomahan/p/9693975.html
Copyright © 2011-2022 走看看