• 链表笔记之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;
    }

  • 相关阅读:
    SpringData JPA接口总结
    使用allatori混淆代码
    Oracle查看表空间大小
    Mac常用命令
    Web.config或App.config下section
    ansi、unicode、UCS、UTF等概念(转)
    强名称程序集与GAC
    指针和引用的区别(转)
    .NET程序员应该知道些什么(转)
    dispose,null和close的区别
  • 原文地址:https://www.cnblogs.com/fx2008/p/2203419.html
Copyright © 2020-2023  润新知