Пример #1
0
/* --- Function: void search_node(Slist lst) --- */
void search_node(Slist lst)
{
  int tmp;
  char mess[BUFSIZ];

  do
    {
      my_clearscrn();
      printf("--- SEARCH NODE ---\n");
      printf("\nCurrent list status(%d nodes): ", SLISTsize(lst));
      SLISTtraverse(lst, print, SLIST_FWD);

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

      if (tmp == -1)
        break;

      if (SLISTfindnode(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
int CHTBLlookup(const CHtbl htbl, void **data)
{
  int bucket;
  SlistNode tmpnode;

  /* Hash the key */
  bucket = htbl->h(*data) % htbl->buckets;

  if ((tmpnode = SLISTfindnode(htbl->table[bucket], *data))) /* Data found */
    {
      *data = SLISTdata(tmpnode); /* Pass data back to caller */
      return 0;
    }

  return -1;
}
Пример #3
0
/* --- Function: void ins_nodes(Slist list) --- */
void ins_nodes(Slist list)
{
  int tmp, *pi;
  SlistNode node;
  char mess[BUFSIZ];

  do
    {
      my_clearscrn();
      printf("--- ADD NODE - WITH DATA=99 - AFTER USER-SPECIFIED NODE ---\n");
      printf("\nCurrent list status(%d nodes): ", SLISTsize(list));
      SLISTtraverse(list, print, SLIST_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 = SLISTfindnode(list, &tmp)) != NULL) /* Node found */
        {
          /* Insert node after first occurance of user-specified node */
          pi = (int *)malloc(sizeof(int));
          MALCHK(pi);

          *pi = 99;

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