Exemplo n.º 1
0
struct node *insert_data(int x, struct node *p)
{
  if (p == NULL) {
    p = (struct node *)malloc(sizeof(struct node));
    if (p == NULL) {
      printf("Out of memory\n");
      exit(1);
    }
    p->data = x;
    p->left = NULL;
    p->right = NULL;

    return p;
  }

  if (x == p->data)
    return p;

  if (x < p->data)
    p->left = insert_data(x, p->left);
  else
    p->right = insert_data(x, p->right);

  return p;
}
Exemplo n.º 2
0
int
main (int argc,
      char *argv[])
{
  int i;
  NODE *s;
  NODE *temp;

  data_dis(&head);
  for (i=0; i<7; i++)
    {
      s = (NODE *)malloc (sizeof(NODE));
      s->data = i + 1;
      insert_data(&head, s);
      data_dis(&head);
    }

  temp = (NODE *)malloc(sizeof(NODE));
  temp->data = 8;
  for (s=head.next; s->data != 6; s=s->next);
  insert_data(s, temp);

  data_dis(&head);

  return 0;
}
Exemplo n.º 3
0
void sys_init(void)

{
	int i;
	str_pword pword;

	initlist(&word_list[0]);
	word_list[0].data = 0;
	current_list = (plist) malloc(sizeof(list));

	index_list[0] = (plist) malloc(sizeof(list));
	pword=(str_pword)malloc(sizeof(str_word));
	pword->freq = 0;
	pword->word[0] = 'a' + i;
	pword->word[1] = '\0';
	insert_data(&word_list[0], i + 1,pword);
	index_list[0] = &word_list[0];
	index_list[0] = index_list[0]->next;

	for(i = 1; i < 27;i++){
		index_list[i] = (plist) malloc(sizeof(list));
		pword=(str_pword)malloc(sizeof(str_word));
		pword->freq = 0;
		pword->word[0] = 'a' + i;
		pword->word[1] = '\0';
		insert_data(&word_list[0], i + 1,pword);
		index_list[i] = index_list[i - 1]->next;
		//pword = index_list[i]->data;
		//printf("%d\n", pword->freq);
	}
}
Exemplo n.º 4
0
int main()
{
 Link *Head =NULL;
 insert_data(&Head,10);  //삽입
 insert_data(&Head,20);  //삽입
 insert_data(&Head,30);  //삽입
 insert_data(&Head,40);  //삽입
 modify_data(Head,20,22);  //수정  20을22로변경
 delete_data(&Head,20);  //삭제//20이라는 데이터를 삭제해라
 search_data(Head,22);  //검색  //22라는데이터를검색(출력값은 데이터와 노드의 주소)
 print_data(Head);  //출력 현재존재하는 노트의 데이터가 모두 출력
 add_data(Head,22,26);  //추가 //22뒤에 26을 추가
 print_data(Head);
 return 0;
}
Exemplo n.º 5
0
int main(){
	NODE *node = 0;
	int i;
	int height;
	int in;
	NODE *temp = 0;

	int a[] = {6,3,1,5,7,12};
	display(root);
	for(i=0; i<6; i++){
		insert_data(a[i]);
		display(root);
	}
	insert_data(9);
	display(root);
	printf("Tree height test\n");
	getchar();

	//height = get_height(root);
	//printf("root height : %d\n", height);
	
/*	while(1){
		printf("input the node data(exit -1):");
		scanf("%d",&in));
		if(in == -1){
			printf("exit\n");
			break;
		}	
		temp->data = in;
		height = get_height(temp);
		printf("%d의 높이: %d\n", temp->data, height);
		temp = 0;
		height = 0;
	}*/
	while(1){
		printf("input the node data(exit -1) : ");
		scanf("%d", &in);
		fflush(stdin);
		if(in==-1) break;
		node = search(root, in);
		height = get_height(node);
		printf("%d의 높이는 %d\n", in, height);
		height = get_balance(node);
		printf("%d의 밸런스 값 : %d\n", in ,height);
		getchar();
	}
	return 0;	
}
Exemplo n.º 6
0
void test_insert(splay_tree* t, int data){
  print_tree(*t);
  printf("\n");
  *t =insert_data(*t, data);
  print_tree(*t);
  printf("\n");
}
Exemplo n.º 7
0
void insert(char *database_name, char *table_name, void *data) {
    if (true == insert_data(database_name, table_name, data)) {
        printf("insert \"%s\" in \"%s\" \n", data, table_name);
    } else {
        printf("failed to insert \"%s\" in \"%s\" \n", data, table_name);
    }
}
Exemplo n.º 8
0
static void
prepare_data(void)
{
  create_documents_table();
  create_terms_table();
  insert_data();
}
Exemplo n.º 9
0
WBXML_DECLARE(WB_BOOL) wbxml_buffer_insert_cstr(WBXMLBuffer *to, WB_UTINY *str, WB_ULONG pos)
{
    if ((to != NULL) && (str != NULL) && !to->is_static)
        return insert_data(to, pos, str, WBXML_STRLEN(str));

    return FALSE;
}
void
print_with_csv_format( void *param, size_t entries, const topology_link_status *s ) {
  size_t i;

  UNUSED( param );

  debug( "topology: entries %zu", entries );

  list_element *link;
  create_list( &link );

  for ( i = 0; i < entries; i++ ) {
    insert_data( &link, &s[ i ] );
  }

  printf( "f-dpid,f-port,t-dpid,t-port,stat\n" );
  list_element *element;
  for ( element = link; element != NULL; element = element->next ) {
    print_link_status( element->data );
  }

  delete_list( link );

  stop_trema();
}
Exemplo n.º 11
0
WBXML_DECLARE(WB_BOOL) wbxml_buffer_insert(WBXMLBuffer *to, WBXMLBuffer *buffer, WB_ULONG pos)
{
    if ((to != NULL) && (buffer != NULL) && !to->is_static)
        return insert_data(to, pos, buffer->data, buffer->len);

    return FALSE;
}
Exemplo n.º 12
0
int
main(int argc, char* argv[])
{
	clock_t tstart, tend;
	sqlite3* phandle = NULL;

	create_db(&phandle);

	tstart = clock();
	start_transation(phandle);
	insert_data(phandle);
	end_transation(phandle);
	tend = clock();

	printf("transaction %lus\n", (tend-tstart)/CLOCKS_PER_SEC);

	tstart = clock();
//	insert_data(phandle);
	tend = clock();

	printf("insert %lus\n", (tend-tstart)/CLOCKS_PER_SEC);


	return EXIT_SUCCESS;
}
Exemplo n.º 13
0
static void test_dbd_generic(abts_case *tc, apr_dbd_t* handle, 
                             const apr_dbd_driver_t* driver)
{
    void* native;
    apr_pool_t *pool = p;
    apr_status_t rv;

    native = apr_dbd_native_handle(driver, handle);
    ABTS_PTR_NOTNULL(tc, native);

    rv = apr_dbd_check_conn(driver, pool, handle);

    create_table(tc, handle, driver);
    select_rows(tc, handle, driver, 0);
    insert_data(tc, handle, driver, 5);
    select_rows(tc, handle, driver, 5);
    delete_rows(tc, handle, driver);
    select_rows(tc, handle, driver, 0);
    drop_table(tc, handle, driver);

    test_escape(tc, handle, driver);

    rv = apr_dbd_close(driver, handle);
    ABTS_ASSERT(tc, "failed to close database", rv == APR_SUCCESS);
}
Exemplo n.º 14
0
int insert_keylist( struct AffWriter_s *w, const char *list_fname )
{
    char buf[49152];
    char *fargv[3];
    FILE *list;
    int num;
    if( 0 == strcmp( list_fname, "-" ) )
    {
        list = stdin;
        if( ferror( list ) )
        {
            fprintf( stderr, "%s: bad stdin stream\n", __func__ );
            return 1;
        }
    }
    else
    {
        if( NULL == ( list = fopen( list_fname, "r" ) ) )
        {
            fprintf( stderr, "%s: cannot open %s\n", __func__, list_fname );
            return 1;
        }
    }
    while( NULL != fgets( buf, sizeof(buf), list ) )
    {
        if( '\n' != buf[strlen(buf)-1] )
        {
            fprintf( stderr, "%s: line too long, skipping\n", __func__ );
            while( NULL != fgets( buf, sizeof(buf), list ) )
                if( '\n' == buf[strlen(buf)-1] )
                    break;
            continue;
        }
        num = split_farg( buf, 3, fargv );
        if( num < 0 )
        {
            fprintf( stderr, "%s: unexpected result of split_farg; exiting\n",
                     __func__ );
            goto errclean_r;
        }
        if( num == 0 )
            continue;
        if( num < 3 )
        {
            fprintf( stderr, "%s: syntax error: need 3 names, only %d given\n",
                     __func__, num );
            goto errclean_r;
        }
        if (insert_data(w, fargv[1], fargv[2], fargv[0]))
            goto errclean_r;
    }
    fclose( list );
    return 0;

errclean_r:
    fclose( list );
    return 1;
}
Exemplo n.º 15
0
  void serialize(std::vector<byte> & v) const {
    insert_obj(v, sizeof(WORD), _pt_size);

    auto font_name = widen(_name);
    insert_data(v, 1,
                (byte *) font_name.c_str(),
                (byte *) (font_name.c_str() +
                          font_name.size() + 1));
  }
Exemplo n.º 16
0
void easy_sqlite_table::insert_3_strings(std::string str1, std::string str2, std::string str3, std::string schema) {
    std::ostringstream oss;
    oss << "( ";
    oss << "'" << str1 << "', ";
    oss << "'" << str2 << "', ";
    oss << "'" << str3 << "'";
    oss <<")";
    insert_data(oss.str());
}
Exemplo n.º 17
0
WBXML_DECLARE(WB_BOOL) wbxml_buffer_append_char(WBXMLBuffer *buffer, WB_UTINY ch)
{
    WB_UTINY c = ch;

    if ((buffer == NULL) || buffer->is_static)
        return FALSE;

    return insert_data(buffer, buffer->len, &c, 1);
}
Exemplo n.º 18
0
WBXML_DECLARE(WB_BOOL) wbxml_buffer_append_data_real(WBXMLBuffer *buffer, const WB_UTINY *data, WB_ULONG len)
{
    if ((buffer == NULL) || buffer->is_static)
        return FALSE;

    if ((data == NULL) || (len == 0))
        return TRUE;

    return insert_data(buffer, buffer->len, data, len);
}
Exemplo n.º 19
0
//修改指定元素的值为最新的值
void modify_data(Tree* pt,int old_data,int new_data)
{
	//1.删除旧节点元素值
	int res = delete_data(pt,old_data);
	if(-1 == res)
	{
		printf("元素%d不存在,则修改失败\n",old_data);
		return;//结束当前函数
	}
	//2.插入新节点元素值
	insert_data(pt,new_data);
}
Exemplo n.º 20
0
static void move_item(struct btree_page *from, int from_pos,
		      struct btree_page *to, int to_pos)
{
	if (from->height)
		insert_ptr(to, to_pos, PAGE_KEY(from, from_pos),
			   *PAGE_PTR(from, from_pos));
	else
		insert_data(to, to_pos, PAGE_KEY(from, from_pos),
			    PAGE_DATA(from, from_pos));

	delete_item(from, from_pos);
}
Exemplo n.º 21
0
int
main (int argc,
      char *argv[])
{
  int i;
  int buff[7] = {5, 3, 4, 7, 6, 1, 2};

  for (i=0; i<7; i++)
    {
      insert_data(buff[i]);
  //    print(root);
    }

  int row = -1, col = 0;
//  __fill(root, &row, &col);
//  print(root);
  root = __bal(buff, 7);
  print(root);


  /* 오전 수업
  printf("--------------------\n");
  in_order (root);
  printf("--------------------\n");
  display (root);
  printf("--------------------\n");
  indent_display (root);
  printf("--------------------\n");
  display_2 (root);

  int (*arr)[10];
  arr = __display(root);

  for (i=0; i<3; i++)
    {
      for (j=0; j<10; j++)
        {
          if (arr[i][j] == 0)
            {
              printf("%4c", ' ');
            }
          else {
            printf("%4d", arr[i][j]);
          }
        }
      printf("\n");
    }
  puts("-------------------------------");
  */

  return 0;
}
Exemplo n.º 22
0
      tImgLinear& tImgLinear::operator=( tImgLinear const& imgIn ) {
         if( this != & imgIn ) {
            _description = imgIn._description;
            _palette = imgIn._palette;
            _size = imgIn._size;
            _ImgFormat = imgIn._ImgFormat;
            alloc_data_buffer();
            insert_data( imgIn.get_data(), bytes(), 0 );
         }

         return *this;

      }
Exemplo n.º 23
0
 tImgLinear::tImgLinear( tImgLinear const& imgIn ):
    _data( nullptr ),
    _description( imgIn._description ),
    _is_allocated( false ),
    _row_pointer(),
    _palette( imgIn._palette ),
    _ImgFormat(),
    _size() {
    _size = imgIn._size;
    _ImgFormat = imgIn._ImgFormat;
    alloc_data_buffer();
    insert_data( imgIn.get_data(), bytes(), 0 );
 }
Exemplo n.º 24
0
int create_node()
{
	struct node *ptr;
	ptr=(struct node*) malloc(sizeof(struct node));
	ptr->next=ptr->prev=NULL;
	insert_data(ptr);
	if(c==0)
	{
		head.next=ptr;
		c=1;
	}
	return 0;
}
Exemplo n.º 25
0
 void serialize(std::vector<byte> & v) const {
   if (_is_title) {
     auto text_item_title = widen(_title);
     insert_data(v, sizeof(WORD),
                 (byte *) text_item_title.c_str(),
                 (byte *) (text_item_title.c_str() +
                           text_item_title.size() + 1));
   }
   else {
     const uint16_t text_item_rsrc_id[] =
       {0xffff, _rsrc_id};
     insert_obj(v, sizeof(WORD), text_item_rsrc_id);
   }
 }
Exemplo n.º 26
0
		std::string SqliteDao::save()
		{
			int ret = 0;

			start_transaction();

            int table_num = table_manager_->get_schema_manager()->get_table_num();

            for (int i = 0; i < table_num; i++)
            {
			    db_mm::TableIndex* table_index = table_manager_->get_table_index(i);
			    db_mm::TableIndex::RowIndexIter row_iter = table_index->iter();

                if (!table_index->has_data())
                {
                    continue;
                }

			    db_mm::RowIndex* row_index = NULL;

			    while (0 == row_iter.get_next(row_index) && 0 == ret)
			    {
			    	if (db_mm::DELETE_ROW == row_index->get_row_stat())
			    	{
			    		ret = delete_data(row_index);
			    	}

			    	else if (db_mm::UPDATE_ROW == row_index->get_row_stat())
			    	{
			    		if (0 == ret && 0 == (ret = delete_data(row_index)))
			    		{
			    			ret = insert_data(row_index);
			    		}
			    	}
			    }
            }

			if (0 == ret)
			{
				commit();
			}

			else
			{
				error_msg_ = sqlite3_errmsg(sqlite_);
				roll_back();
			}

			return error_msg_;
		}
Exemplo n.º 27
0
int main()
{
	print_ll();
	insert_data(10);
	print_ll();

	insert_data(20);
	insert_data(30);
	insert_data(15);
	insert_data(40);
	insert_data(50);
	insert_data(25);
	insert_data(60);
	print_ll();

	delete_data(100);
	print_ll();

	delete_data(15);
	print_ll();

	delete_data(25);
	print_ll();

	delete_data(10);
	print_ll();

	delete_data(20);
	print_ll();

	delete_data(60);
	print_ll();

	delete_data(50);
	print_ll();

	delete_data(30);
	print_ll();

	delete_data(40);
	print_ll();

	delete_data(40);
	print_ll();

	return 0;
}
Exemplo n.º 28
0
int main(void)
{
	//创建有序二叉树,并且进行初始化
	Tree tree;
	tree.root = NULL;
	tree.cnt = 0;

	insert_data(&tree,50);
	travel_data(&tree);//50
	insert_data(&tree,70);
	travel_data(&tree);//50 70
	insert_data(&tree,20);
	travel_data(&tree);//20 50 70
	insert_data(&tree,60);
	travel_data(&tree);//20 50 60 70

	printf("------------------------\n");
	printf("%s\n",empty(&tree)?"有序二叉树已经空了":"有序二叉树没有空");//没有空
	printf("%s\n",full(&tree)?"有序二叉树已经满了":"有序二叉树没有满");//没有满
	printf("有序二叉树中根节点的元素值是:%d\n",get_root(&tree));//50
	printf("有序二叉树中节点元素的个数是:%d\n",size(&tree));//4

	printf("----------------------\n");
	delete_data(&tree,50);
	travel_data(&tree); //20 60 70

	modify_data(&tree,50,200);//修改失败
	modify_data(&tree,20,200);//修改成功
	travel_data(&tree);//60 70 200
	
	printf("-----------------------\n");
	clear_data(&tree);
	travel_data(&tree); //啥也没有
	printf("有序二叉树中节点元素的个数是:%d\n",size(&tree));//0
	return 0;
}
Exemplo n.º 29
0
static int jose(int n, int m)
{
	int i;

	for (i=1; i<=n; ++i)
		insert_data(i);

	while(start->next != start)
	{
		for (i=1; i<m; ++i)
			start = start->next;
		delete_data(start->data);
	}
	return start->data;

}
Exemplo n.º 30
0
int main()
{
	int i;
	NODE temp[7];
	init(&head);
	display(&head);
	for (i = 0; i<7; i++)
	{
		temp[i].data = i + 1;
		insert_data(temp + i, &head);
		display(&head);
	}
	reverse(&head);
	display(&head);
	reverse(&head);
	display(&head);
	return 0;
}