美文网首页
链表函数

链表函数

作者: 持之以蘅 | 来源:发表于2020-03-10 11:43 被阅读0次
#include"node.h"
#include<stdio.h>
#include<stdlib.h>

//typedef struct _node{
//  int value;
//  struct _node *next;
//} Node; 

typedef struct _list{
    Node *head;//不要写成struct _list *head;
    //Node *tail;
} List;
void add(List *pList,int number);

int main(int argc, char const *argv[])
{
    List list;
     
    list.head=NULL;//使用结构体,以前:Node *head=NULL;
    int number;
    do{
        scanf("%d",&number);
        if(number!=-1){
            
            list.head=add(&list,number);
            }
        }while(number!=-1);
     return 0; 
} 

void add(List *pList,int number)
{ 
    //add to linked-list
    Node *p=(Node*)malloc(sizeof(Node));
    p->value=number;
    p->next=NULL;
    //find the last
    Node *last=pList->head;//以前Node *last=head;
    if(last)//last不为空
    {
        while(last->next)
        {
            last=last->next;
        }
            //attach
         last->next=p;
        
     } 
     else
     {
        pList->head=p; 
     }
     
}   
    

有报错,还未解决

相关文章

  • 链表复习(二)

    删除链表函数: 反转链表函数: 循环链表: 注意head代表头结点,也代表尾节点

  • JS 实现链表

    Node 为创建节点的构造函数;LinkedList 为链表操作函数的构造函数。对链表的操作包括:插入节点、移除节...

  • 链表函数

    有报错,还未解决

  • C语言指针部分说明

    二级指针 函数指针 数组和链表 访问数组 访问链表 Makefile

  • 4-1 单链表逆转

    本题要求实现一个函数,将给定的单链表逆转。函数接口定义: 其中List结构定义如下: L是给定单链表,函数Reve...

  • 系统编程(3)

    使用链表实现进出排队系统 链表的函数的声明 对于链表头文件各种操作具体功能的实现

  • LeetCode基础算法-链表

    # LeetCode基础算法-链表 LeetCode 链表 1. 删除链表中的节点 请编写一个函数,使其可以删除某...

  • 面试题35. 复杂链表的复制

    复杂链表的复制 题目描述 请实现 copyRandomList 函数,复制一个复杂链表。在复杂链表中,每个节点除了...

  • 11.24习题

    44.翻转链表 写一个函数,功能为把传进来的链表翻转,并测试。 45.写一个函数,把链表倒数第k个节点删除,并测试。

  • iOS标准库中常用数据结构和算法之链表

    ⛓双向链表 功能:对双向链表进行添加、删除功能。 头文件:#include +- 平台:POSIX 函数签名: ...

网友评论

      本文标题:链表函数

      本文链接:https://www.haomeiwen.com/subject/wsfwdhtx.html