zoukankan      html  css  js  c++  java
  • 用单链表实现一个模糊搜索, 待补充

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    typedef struct node_s{
            char *data;
            struct node_s *next;
    }node_t;
    
    node_t *create(){
            node_t *p = calloc(1, sizeof(node_t));
            return p;
    }
    
    
    int insert(node_t *head, const char *data){
            node_t *new = create();
            if(!new){
                    return -1;
            }
            new->data = strdup(data);
            new->next = head->next;
            head->next = new;
            return 0;
    }
    
    int clear(node_t *head){
            node_t *p_next;
            if(!head){
                    return -1;
            }
            while(head->next != NULL){
                    p_next = head->next;
                    if(head->data){
                            free(head->data);
                    }
                    free(head);
                    head=p_next;
            }
            return 0;
    }
    
    #define foreach(head, a_unit) 
            for(head = head->next, a_unit = head; head != NULL; head = head->next, a_unit = head)
    
    int main(){
            node_t *head = create();
            insert(head, "a");
            insert(head, "b");
            insert(head, "c");
    
            node_t *a_unit; 
            foreach(head, a_unit){
                    printf("%s
    ", a_unit->data);
            }
    
            clear(head);
    }
  • 相关阅读:
    P1006 传纸条
    P1387 最大正方形
    P1417 烹调方案
    P1052 过河
    P1063 能量项链
    P1736 创意吃鱼法
    P1156 垃圾陷阱
    P1220 关路灯
    @P1373 小a和uim之大逃离
    【leetcode】Interleaving String
  • 原文地址:https://www.cnblogs.com/bai-jimmy/p/5463218.html
Copyright © 2011-2022 走看看