示例#1
0
文件: tst.cpp 项目: malloc47/term-do
void TST::searchp(TSTp p,string *s, unsigned int pos, list_t *output) {
  if(!p || s->empty()) return;
  char c = downcase(pos < s->length() ? s->at(pos) : 0);
  if(c < p->val)
    searchp(p->left,s,pos,output);
  else if(c > p->val)
    searchp(p->right,s,pos,output);
  else {
    if(pos==s->length()-1)
      sort(p->middle,output);
    searchp(p->middle,s,pos+1,output);
  }
}
示例#2
0
int
main ()
{
  /* Must be power of two minus 1.  */
  int size = 0x7ffff;
  struct T *trees = (struct T *) malloc (size * sizeof (struct T));
  if (trees == NULL)
    return 0;
  int i, l = 1, b = 0;
  for (i = 0; i < size; i++)
    {
      if (i == l)
	{
	  b = l;
	  l = l * 2 + 1;
	}
      trees[i].val = i;
      trees[i].children[0] = l == size ? NULL : &trees[l + (i - b) * 2];
      trees[i].children[1] = l == size ? NULL : &trees[l + (i - b) * 2 + 1];
    }
  for (i = 0; i < 50; i++)
    {
      int v = random () & size;
      if (searchp (&trees[0], v) != &trees[v])
	abort ();
    }
  free (trees);
  return 0;
}
示例#3
0
int		ft_printf(const char *format, ...)
{
	int			len;
	va_list		args;

	len = 0;
	if (format)
	{
		va_start(args, format);
		len = searchp(format, args);
	}
	va_end(args);
	return (len);
}
示例#4
0
文件: tst.cpp 项目: malloc47/term-do
list_t TST::searchp(string s) { 
  list_t output;
  if(s.size() > 0) searchp(root,&s,0,&output);
  else output=sort();
  return output;
}