Example #1
0
/* 测试顺序表存储结构 */
void fun_seqList()
{
	SeqList *L = init_SeqList();
	for (int i = 1; i <= 10; i++)
		Insert_SeqList(L, i, i);
	Delete_SeqList(L, 3);
	Delete_SeqList(L, 5);
	Display_SeqList(L);
	free(L);
}
Example #2
0
int main()
{ 
  printf("------main-------\n");
  SeqList *L = Init_SeqList();
  printf("---insert begin---\n");
  printf("L->last:%d\n", L->last);
  for (int i = 0; i <= 10; ++i)
  {
    int j = Insert_SeqList(L, i, i);
    if (j == 0)
      printf("%d:insert success\n", i);
    else
      printf("%d:insert failure\n", i);
  }
  int j = Delete_SeqList(L, 5);
  int k = Locate_SeqList(L, 4);
  printf("k:%d\n", L->last);
  if (k != -1)
    printf("locate success\n");
  else
    printf("locate failure\n");
  int m = Locate_SeqList(L, 5);
  if (m == 0)
    printf("locate success\n");
  else
  printf("locate failure\n");
  free(L);
  return 0;
}
Example #3
0
int main ()
{
	SeqList La, Lb, Lc ;
	elemtype x, position ;

	
	Init_SeqList ( &La ) ;		
	Creat_SeqList ( &La ) ;			

	// 获得3位置数据元素
	printf ( "\n\t\t\t-- GetElem --\n" ) ;
	GetElem ( &La, 3, &x ) ;	
	sleep ( 1 ) ;
	printf ( "The element is %d.\n", x ) ;

	// 获得查找数据的位置
	printf ( "\n\t\t\t-- Locate --\n" ) ;
	position = Locate ( &La, x ) ;	
	sleep ( 1 ) ;
	if ( position == ERROR )
		printf ( "The postion is ERROR.\n" ) ;
	else if ( position == 0 ) 
		printf ( "Not find.\n" ) ;
	else 
		printf ( "The element's position is %d.\n", position ) ;

	// 插入数据元素
	printf ( "Please input your insert_elem and position:" ) ;
	scanf ( "%d", &x ) ;
	scanf ( "%d", &position ) ;
	Insert_SeqList ( &La, position, &x ) ;	
	Output_SeqList ( &La ) ;

	// 删除数据元素
	printf ( "Please input your delete_position:" );
	scanf ( "%d", &position ) ;
	Delete_SeqList ( &La, position, &x ) ;	
	printf ( "The delete_elem is %d.\n", x ) ;

	// 充值线性表
	Reserve_SeqList ( &La ) ;		

	Output_SeqList ( &La ) ;		

	
	Init_SeqList ( &Lb ) ;
	Creat_SeqList ( &Lb ) ;
	Output_SeqList ( &Lb ) ;


	// 合并线性表
	Merge ( &La, &Lb, &Lc ) ;
	Output_SeqList ( &Lc ) ;

	return 0 ;
}