非常精彩的链表操作 --git按键的屏蔽部分 头插/del

#include "button.h"

static struct button* Head_Button = NULL;

//拷贝指定长度字符串
static char *StrnCopy(char *dst, const char *src, uint32_t n)
{
  if (n != 0)
  {
    char *d = dst;
    const char *s = src;
    do
    {
        if ((*d++ = *s++) == 0)
        {
            while (--n != 0)
                *d++ = 0;
            break;
        }
    } while (--n != 0);
  }
  return (dst);
}

static void List_Button_Add(Button_t* btn)
{
  btn->Next = Head_Button;
  Head_Button = btn;
}
//删除
static void List_Button_Delete(Button_t *btn)
{
  struct button** curr;
  for(curr = &Head_Button; *curr;) 
  {
    struct button* entry = *curr;
    if (entry == btn) 
      *curr = entry->Next;
    else
      curr = &entry->Next;
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_42381351/article/details/85276566