Esempio n. 1
0
int main()
{
	SL_DataType i;
	SeqList sl;
	SL_init(&sl,5);
	printf("长度:%d\n",SL_getLen(sl));
	for(i=0;i<8;++i)
		SL_insert(&sl,i,0);
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	SL_insert(&sl,5,6);
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	SL_insert(&sl,5,1);
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	printf("%d\n",SL_delete(&sl,100));
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	printf("%d\n",SL_delete(&sl,5));
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	printf("%d\n",SL_remove(&sl,100));
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
	printf("%d\n",SL_remove(&sl,5));
	print(sl);
	printf("长度:%d\n",SL_getLen(sl));
    SL_clear(&sl);
	return 0;
}
Esempio n. 2
0
/**
 * Inserts an item into the global structure list.
 *
 * It adds a new region to the list: its start point, its end point, its annotation.
 *
 * Combines SL_seek(), SL_insert_at_point() and ambiguity resolution.
 */
void
SL_insert(int start, int end, char *annot)
{
  SL point, item;

  point = SL_seek(start);
  if (point == NULL) {
    item = SL_insert_after_point(start, end, annot); /* insert item at start of list */
  }
  else if ((point->start <= start) && (start <= point->end)) {
    /* start is within the previous region stored in point */
    if ((point->start < start) || (point->end > end)) {
      /* overlap: don't insert
       * because either the start points don't match, or the old region is longer */
      return;
    }
    else {
      /* point->start == start && point->end <= end -->
       * overlap: overwrite previous entry
       * because the start points match, and the new region is as long or longer */
      item = SL_insert_after_point(start, end, annot);
      SL_delete(point); /* this re-establishes list ordering */
    }
  }
  else {
    /* non-overlapping: simply insert new region after point */
    item = SL_insert_after_point(start, end, annot);
  }

  /* new item may overlap one or more of the following ones, which we must delete */
  point = item->next;
  while ((point != NULL) && (point->start <= item->end)) { /* (point->start > item->start) implied by insertion above */
    SL_delete(point);
    point = item->next;
  }
}