链表头插法

 

head_handle = null;

int button_start(struct Button* A)
{
  struct Button* target = head_handle;
  while(target) {//这个循环用来判断是不是重复的节点
    if(target == A) return -1; //already exist.
    target = target->next;
  }
  A->next = head_handle;//核心内容就是这句和下句
  head_handle = A;
  return 0;
}

 button_start(A);

 button_start(B);

 button_start(C);

 

posted @ 2022-08-23 10:11  只因在风中  阅读(58)  评论(0编辑  收藏  举报