コード例 #1
0
ファイル: demo02.c プロジェクト: Sukumi/levawc
/* --- Function: void search_node(Dlist lst) --- */
void search_node(Dlist lst)
{
  int tmp;
  char mess[BUFSIZ];

  do
    {
      my_clearscrn();
      printf("--- SEARCH NODE ---\n");
      printf("\nCurrent list status(%d nodes): ", DLISTsize(lst));
      DLISTtraverse(lst, print, DLIST_FWD);

      tmp = read_int("\nEnter keydata for node to be found (-1=Quit): ", 0, 0);

      if (tmp == -1)
        break;

      if (DLISTfindnode(lst, &tmp) == NULL) /* Node not found.. */
        {
          sprintf(mess, "Node %d NOT found..!", tmp);
          prompt_and_pause(mess);
        }
      else
        {
          /* Search succesful - notify user.. */
          sprintf(mess, "Node %d FOUND!", tmp);
          prompt_and_pause(mess);
        }
    } while (TRUE);
}
コード例 #2
0
ファイル: dlist.c プロジェクト: AsamQi/levawc
int DLISTfind_remove(Dlist list, void **data)
{
  DlistNode member;

  /* If match-callback not set */
  if (list->match == NULL)
    return -2;

  /* Search list sequentially.. */
  member = DLISTfindnode(list, *data);

  if (member == NULL) /* Node not found */
    return 1;

  /* Perform the removal.. */
  return DLISTremove(list, member, data);
}
コード例 #3
0
ファイル: demo02.c プロジェクト: Sukumi/levawc
/* --- Function: void ins_nodes(Dlist list) --- */
void ins_nodes(Dlist list)
{
  int tmp, *pi;
  DlistNode node;
  char mess[BUFSIZ];

  do
    {
      my_clearscrn();
      printf("--- ADD NODE WITH DATA=99 - AFTER USER-SPECIFIED NODE ---\n");
      printf("\nCurrent list status(%d nodes): ", DLISTsize(list));
      printf("\nAscending : ");
      DLISTtraverse(list, print, DLIST_FWD);

      tmp = read_int("\nEnter (key)data, after which new node(key=99) will be inserted (-1=Quit): ", 0, 0);

      if (tmp == -1)
        break;

      if ((node = DLISTfindnode(list, &tmp)) != NULL) /* Node found */
        {
          /* Insert node after first occurance of user-specified node */
          pi = (int *)malloc(sizeof(int));
          MALCHK(pi);

          *pi = 99;

          if ((DLISTinsnext(list, node, pi)) != OK)
            {
              printf("\nFatal error - exiting...");
              DLISTdestroy(list);
              exit(-1);
            }
          else
            {
              sprintf(mess, "Node 99 will be inserted after node %d", *(int *)DLISTdata(node));
              prompt_and_pause(mess);
            }
        }
      else
        {
          sprintf(mess, "Error: Node %d not found...!", tmp);
          prompt_and_pause(mess);
        }
    } while (TRUE);
}