鱼C论坛

 找回密码
 立即注册
查看: 4344|回复: 11

[知识点备忘] S1E47:单链表3

[复制链接]
发表于 2017-4-9 03:49:00 | 显示全部楼层 |阅读模式
购买主题 已有 12 人购买  本主题需向作者支付 5 鱼币 才能浏览
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2019-6-11 15:02:30 | 显示全部楼层
谢谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-6-11 15:03:05 | 显示全部楼层
谢谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-8-16 18:41:28 | 显示全部楼层
本帖最后由 清尘yt 于 2019-8-16 19:25 编辑
  1. void insertNode(struct Node **head,int value)
  2. {
  3.         struct Node *previous,*new,*current;
  4.         previous=NULL;
  5.         current=*head;
  6.         new=(struct Node *)malloc(sizeof(struct Node));
  7.         if(new==NULL)
  8.         {
  9.                 printf("内存分配失败!");
  10.                 exit(1);
  11.         }
  12.         while(current!=NULL && current->value<value)
  13.         {
  14.                 previous=current;
  15.                 current=current->next;
  16.         }
  17.         if(previous==NULL)
  18.         {
  19.                 *head=new;
  20.         }
  21.         else
  22.         {
  23.                 previous->next=new;
  24.         }
  25.         new->value=value;
  26.         new->next=current;
  27. }
复制代码
  1. void deleteNode(struct Node **head,int value)
  2. {
  3.         struct Node *previous,*current;
  4.         current=*head;
  5.         previous=NULL;
  6.         while(current!=NULL && current->value!=value)
  7.         {
  8.                 previous=current;
  9.                 current=current->next;
  10.         }
  11.         if(current==NULL)
  12.         {
  13.                 printf("找不到!\n");
  14.                 return ;
  15.         }
  16.         else
  17.         {
  18.                 if(previous==NULL)
  19.                 {
  20.                         *head=current->next;
  21.                 }
  22.                 else
  23.                 {
  24.                         previous->next=current->next;
  25.                 }
  26.         }
  27.         free(current);
  28. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2019-9-10 09:13:17 | 显示全部楼层
谢谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-9-15 16:07:42 | 显示全部楼层

找不到主函数里面的内容啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-1-31 22:01:18 | 显示全部楼层
本帖最后由 cslu 于 2020-2-1 12:01 编辑

#include <stdio.h>
#include <stdlib.h>
struct Node
{
        int value;
        struct Node *next;
};


void insertNode(struct Node **head,int value)
{
        struct Node *previous,current,new;
      
               
                current = *head;
        previous = NULL;
      
        
        while(current!= NULL && current->value < value)
        {
                previous=current;
                current=current->next;
        }
        
        new=(struct Node *)malloc(sizeof(struct Node));
        if(new==NULL)
        {
                printf("内存分配失败!");
                exit(1);
        }
        
      
        new->value=value;
        new->next=current;
        
         if(previous==NULL)
        {
                *head=new;
        }
        else
        {
                previous->next=new;
        }
}

void printNode(struct Node *head)
{
        struct Node *current;
       
        current=head;
        while(current!=NULL)
        {
                printf("%d",current->value);
                current=current->next;
        }
        putchar('\n');
}


int main(void)
{
        struct Node *head=NULL;
        int input;
       
        while(1)
        {
                printf("请输入1个整数(输入-1表示结束):");
                scanf("%d",&input);
                if(input==-1)
                {
                        break;
                }
                insertNode(&head,input);
                printNode(head);
        }
       
        return 0;
}
俺不知道哪里还有问题,编译不通过
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

发表于 2020-4-17 10:39:38 | 显示全部楼层
cslu 发表于 2020-1-31 22:01
#include
#include
struct Node

这句:struct Node *previous,current,new;
应该改为: struct Node *previous,*current,*new;
(你少打了两个星号)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-7-25 20:20:14 | 显示全部楼层
阎建伟 发表于 2020-4-17 10:39
这句:struct Node *previous,current,new;
应该改为: struct Node *previous,*current,*new;
(你少打 ...

晓得了,谢谢
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-9-14 20:42:49 | 显示全部楼层
void getInput(struct Person *person);
void outPut(struct Person *person);
void outPutAll(struct Person *person);
void addPerson(struct Person **person);
struct Person  *find(struct Person *person, char input[]);
void findPerson(struct Person **person);
void fixPerson(struct Person *person);
void delPerson(struct Person **person);
void dispPerson(struct Person **person);
void release(struct Person *person);


int main(void)
{
        struct Person *head = NULL;
        int input;
        printf("请按照说明,输入数字进行操作!\n\
                                1.新建联系人。\n\
                                2.查找联系人。\n\
                                3.更改联系人。\n\
                                4.删除联系人。\n\
                                5.显示所有联系人\n\
                                6.退出联系人。\n");

printf("输入数字:");
scanf("%d",&input);
        while(input != 6)
        {
                switch (input)
        {
                case 1: addPerson(&head);break;
                case 2: findPerson(&head);break;
                case 3: fixPerson(head);break;
                case 4: delPerson(&head);break;
                case 5: dispPerson(&head);break;
                case 6: release(head);break;
                //default : printf("输入错误\n");continue;
        }
        putchar('\n');
        printf("输入数字:");
        scanf("%d",&input);
        }
        return 0;
}

写了两天,反复看了无数遍视频,终于写出来了!小甲鱼
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

发表于 2022-5-6 17:57:02 | 显示全部楼层
好好学习才能天天向上!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-7-4 19:57:22 | 显示全部楼层
加油!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-5 09:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表