链表笔记之1

 

#include <stdlib.h>/*标准库函数*/
#include <stdio.h>/*I/O函数*/
#include <string.h>/*字符串函数*/
#include <ctype.h>/*字符操作函数*/
#include "linkedlist.h"
#include "hashtable.h"
#include "queue.h"


typedef struct student
{
    int id;
    char name[15];
} student; //节点定义

//链表的遍历
void print_linked_list(LinkedList* list)
{
    if(list->head == NULL)
    {
        printf("print_link函数执行,链表为空\n");
        return;
    }
    while(list->head!=NULL)
    {
        student* st=(student*)list->head->data;
        printf("%d %s\n",st->id,st->name);
        list->head=list->head->next;
    }
    printf("\n");
}

//链表的结点删除
void delete_linked_list_node(LinkedList* list,int no)
{
    if(list->head == NULL)
    {
        printf("print_link函数执行,链表为空\n");
        return;
    }

    LinkedListNode *node = NULL, *tmp = NULL;
    node=tmp=list->head;

    int id=((student*)node->data)->id;
    if(id==no)
    {
        list->head=node->next;
        free(node);
    }
    else
    {
        while((id!=no)&&(node->next!=NULL))
        {
            id=((student*)node->data)->id;
            tmp = node;
            node = node->next;
        }
        if(id==no)
        {
            tmp->next=node->next;
            free(node);
        }
    }
}

int main(int argc, char *argv[])
{
    /*
    LinkedList *list = NULL;
    list=linked_list_construct();
    int i=0;
    while(i<5)
    {
     LinkedListNode *node=NULL;
     node=(LinkedListNode *)malloc(sizeof(LinkedListNode));
     memset(node,0,sizeof(LinkedListNode));

     student* st=NULL;
     st=(student *)malloc(sizeof(student));
     memset(st,0,sizeof(student));

     st->id=i;
     sprintf(st->name,"%s%d","方欣_",i);
     node->data=st;
     linked_list_append_node(list,node);
     i++;
    }

    //linked_list_remove_node(list,node);
    //linked_list_destroy(list);
    //int ret=linked_list_is_empty(list);
    //printf("%s\n",ret==1?"链表为空":"链表非空");
    delete_linked_list_node(list,2);
    print_linked_list(list);*/


    /*
     HashTable* ht=NULL;
        ht=hash_table_construct(5);
        int j=0;
     while(j<5)
     {
      student* st=NULL;
      st=(student *)malloc(sizeof(student));
      memset(st,0,sizeof(student));
      st->id=j;
      sprintf(st->name,"%s%d","方欣_",j);
      hash_table_add_element(ht,st,j);
      j++;
     }

     int k;
     for(k=0;k<5;++k)
     {
      student* st=NULL;
         st=(student*)hash_table_get_element(ht,k);
      printf("%d %s\n",st->id,st->name);
     }*/

    /*
     hash_table_remove_element(ht,2);
     student* stu=NULL;
        stu=(student*)hash_table_get_element(ht,3);
        if(stu!=NULL)
        {
         printf("%d %s\n",stu->id,stu->name);
        }*/


    //int index=hash_table_get_index(ht,4);
    //printf("%d\n",index);

    //char* code="E:\\fxd\\hd_mw\\src\\dg_ip_program";
//    int index=hash_table_get_hash_code_from_string(code);
//    printf("%d\n",index);

    //hash_table_destroy(ht);

    Queue * qu=queue_construct();//初始化队列
    int j=0;
    while(j<5)
    {
        student* st=NULL;
        st=(student *)malloc(sizeof(student));
        memset(st,0,sizeof(student));
        st->id=j;
        sprintf(st->name,"%s%d","方欣_",j);
        queue_enqueue(qu,st);//入队
        j++;
    }
    int ret;
    ret=queue_length(qu);
    printf("%d\n",ret);

    /*
     queue_destroy(qu);//销毁队列
     ret=queue_is_empty(qu);
     printf("%s\n",ret==1?"队列为空":"队列非空"); */
    /*
    int k;
    for(k=0;k<5;++k)
    {
     student* st=NULL;
     st=(student *)malloc(sizeof(student));
     memset(st,0,sizeof(student));
     st=(student *)queue_dequeue(qu);//出队
     printf("%d %s\n",st->id,st->name);
    }*/
    return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/404842.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

FPGA+NIOS2 Verilog+C 实现一个计算器

用FPGA生成一个32位的MCU软核&#xff0c;生产相应的管脚和资源&#xff0c;在MCU里边用C完成计算器的逻辑和LCD1602、矩阵键盘的编写。2016年的古老存货。 一、硬件和开发环境 FPGA&#xff1a;EP4CE6E22C8 LCD1206液晶&#xff0c;4X4矩阵键盘。quartus 13project_FPGA_NO1…

[react] ES6的语法‘...‘在React中有哪些应用?

[react] ES6的语法...在React中有哪些应用&#xff1f; 向子组件传递props <Demo {...this.props}> redux中参数合并 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关…

用Java Servlets代替CGI

从网络的早期阶段开始&#xff0c;人们就希望他们的网络服务器不仅能够显示静态文档&#xff0c;通用网关接口(CGI) 扩展了服务器的能力&#xff0c;但其代价是增加了额外的处理进程。FastCGI则把外部CGI 处理进程同网络服务器更紧密地集成在一起&#xff0c;另外&#xff0c;对…

C语言中的位域的使用

From: http://dev.yesky.com/374/2645874.shtml 计算机C语言初学者入门讲座   一、位域   有些信息在存储时&#xff0c;并不需要占用一个完整的字节&#xff0c; 而只需占几个或一个二进制位。例如在存放一个开关量时&#xff0c;只有0和1 两种状态&#xff0c; 用一…

Windows 7下实现×××连接自动创建

在完成了Windows XP下自动创建并配置连接后&#xff0c;其实我们还需要对Windows 7下自动配置做一个介绍&#xff0c;因为目前实际上很多企业也已经开始进行了大批量的Windows 7的使用&#xff0c;而且很多用户目前也在逐渐向Windows 7系统迈进&#xff0c;那么如何让Windows 7…

FPGA Verilog实现一个脉冲波形变换

一、波形变换需求 二、思路 &#xff08;1&#xff09;脉冲边沿提取&#xff0c;得到波形的上升沿r_rise和下降沿r_fall &#xff08;2&#xff09;将上升沿r_rise延迟一节拍r_r_rise&#xff0c;r_rise更新上一周期的周期和脉宽并清空上一次的脉冲周期计数和脉宽周期计数&am…

[react] 状态管理器它精髓是什么?

[react] 状态管理器它精髓是什么&#xff1f; 统一的数据管理 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

夺命雷公狗jquery---22-bind为jquery对象绑定多个相关事件

<!DOCTYPE html> <html><head><meta charset"utf-8"><title></title><script src"js/jquery.js"></script><script>//页面载入ready方法$(function(){$(img).bind({mouseover:function(){$(#result…

STM32 DSP库的使用方法

一、工程中如何添加DSP库 在keil5软件中点击 Pack&#xff0c;CMISIS组件选择DSP资源&#xff0c;可以选择Source源码或者Library库导入到项目中&#xff0c;点击OK&#xff0c;可以在项目树中看到该资源已经导入了工程。 二、 如何使用DSP库 DSP库对浮点计算做了优化和增强&…

SharePoint 2010-随机出现的页面性能问题

有个客户, 服务器的配置巨牛, 24核CPU, 64GB内存, 这样的三台机器组成了一个SharePoint 2010的服务器场. 就是这样牛的配置, 出现了性能问题. 看performance log, 发现CPU, 内存都资源非常充裕, 问题发生的时候request/sec的值也非常的低. 问题发生的频率很低, 一天十次以内. …

[react] 在使用react过程中什么时候用HOC?

[react] 在使用react过程中什么时候用HOC&#xff1f; 给组件增加额外的功能 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

C++使用Json作为数据包装格式的通信

From: http://blog.sina.com.cn/s/blog_4ae178ba01014eve.html http://blog.csdn.net/chenziwen/article/details/5785932 Json大家都耳熟能详了吧&#xff1f;现在Json广泛用于各类通信&#xff0c;特别是基于Http协议的通信&#xff0c;一般的服务端动态脚本语言都有库支持…

iOS开发多线程篇—线程的状态

iOS开发多线程篇—线程的状态 一、简单介绍 线程的创建&#xff1a; self.thread[[NSThread alloc]initWithTarget:self selector:selector(test) object:nil]; 说明&#xff1a;创建线程有多种方式&#xff0c;这里不做过多的介绍。 线程的开启&#xff1a; [self.thread star…

Qt 编写应用程序升级的配置文件json 生成工具

通过此工具将需要更新的应用程序和相关目录下的依赖文件配置成json格式的升级文件&#xff0c;客户端版本监控软件通过读取此json文件&#xff0c;对比相应字段&#xff0c;实现自动拉取文件&#xff0c;从而保证客户端应用程序自动更新。 此json文件放在待升级的exe同级目录下…

以太网供电新标准POE+,IEEE802.3at解析

以太网供电新标准POE&#xff0c;IEEE802.3at解析 以太网供电新标准POE&#xff0c;IEEE802.3at一、IEEE 802.3at标准出现的背景为了遵循IEEE 802.3af规范&#xff0c;受电设备(PD)上的PoE功耗被限制为12.95W&#xff0c;这对于传统的IP电话以及网络摄像头而言足以满足需求&am…

C# 6.0 (C# vNext) 的新功能:Expression Bodied Functions and Properties

Expression Bodied Function 它可以用在&#xff1a;methodsuser-defined operatorstype conversionsread-only properties indexers 看下面的样例&#xff1a;public class RgbColor(int r, int g, int b) {public int Red { get; } r;public int Green { get; } g;public i…

[react] 在React中如何避免不必要的render?

[react] 在React中如何避免不必要的render&#xff1f; shouldComponentUpdate、memoization、PureComponent 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

C++的JSON库及使用方法

From: http://blog.csdn.net/moruite/article/details/7310976 VC没有自带的JSON库&#xff0c;所以分享一下如何使用该库http://download.csdn.net/detail/moruite/4104704 1. json.h头文件包含了如下API [cpp] view plaincopy #ifndef CPPTL_JSON_H_INCLUDED # define CP…

流程制造项目中关于销售订单数量与实际产生数量不同时的解决方案

流程制造项目中关于销售订单数量与实际产生数量不同时的解决方案 在流程制造项目中&#xff0c;例如涂料领域&#xff0c;往往实际生产出来的数量与销售订单的数量会产生差异&#xff0c;这种差异是小额值的。 例如客户A下了100KG的涂料&#xff0c;但车间实际生产出来的数量会…

KEIL ARM 6.12 compiler 编译__ASM 错误的解决方法

1、问题 KEIL compiler 设置为 “use default compiler version 5” 可以正确编译以下汇编和C混合代码&#xff0c;更改编译器为V6.12后不识别__ASM关键字&#xff0c;并对汇编语法报错。 替换为 __ASM void MSR_MSP(uint32_t addr) {MSR MSP, r0 BX r14 } 2、解决办法 6.12…