Пример #1
0
void OverrideList::AddTail( OverrideListItem* poliToAdd)
{
	if (poliToAdd==NULL)
	{
		ERROR2RAW("OverrideList::AddTail - NULL parameter");
		return;
	}

	//Get the last item in the list
	OverrideListItem* pliLast=(OverrideListItem*) GetTail();

	//Was there anything in the list?
	if (pliLast!=NULL)				 
	{
		//Yes. So call our InsertAfter function
		InsertAfter(pliLast, poliToAdd);
	}
	else
	{
		//No. So we need do no special checking - simply insert
		//the list item
		List::AddTail(poliToAdd);
	}

	//And add our item after it
	InsertAfter(pliLast, poliToAdd);
	
}
Пример #2
0
void List::InsertInOrder(Node* node) 
{
	if (node == 0)
		throw runtime_error("Invalid node pointer.");

	if (head == 0)
	{
		head = node;
		return;
	}
    if (head->GetValue() > node->GetValue()) 
	{
		InsertAfter(head, node);
        return;
    }

    Node* curr = head;

    while (curr != 0) 
	{ //otherwise, insert after
        if(curr->GetNext() == 0 || curr->GetNext()->GetValue() > node->GetValue()) 
		{
            InsertAfter(curr, node); // this will be consistent with the textbook InsertAfter() function
            break;
		}
        curr = curr->GetNext();
    }
}
Пример #3
0
void
nsScannerBufferList::SplitBuffer( const Position& pos )
  {
    // splitting to the right keeps the work string and any extant token
    // pointing to and holding a reference count on the same buffer.

    Buffer* bufferToSplit = pos.mBuffer;
    NS_ASSERTION(bufferToSplit, "null pointer");

    PRUint32 splitOffset = pos.mPosition - bufferToSplit->DataStart();
    NS_ASSERTION(pos.mPosition >= bufferToSplit->DataStart() &&
                 splitOffset <= bufferToSplit->DataLength(),
                 "split offset is outside buffer");
    
    PRUint32 len = bufferToSplit->DataLength() - splitOffset;
    Buffer* new_buffer = AllocBuffer(len);
    if (new_buffer)
      {
        nsCharTraits<PRUnichar>::copy(new_buffer->DataStart(),
                                      bufferToSplit->DataStart() + splitOffset,
                                      len);
        InsertAfter(new_buffer, bufferToSplit);
        bufferToSplit->SetDataLength(splitOffset);
      }
  }
Пример #4
0
void DisplayElement::SortByZIndex (void)
{
DisplayElement *unsorted = mpFirstChild, *child, *leastOfThese, *sorted = 0;

	// Bubble sort for now, just to test that it works
	while (unsorted)
	{
		leastOfThese = unsorted;
		child = unsorted;
		while (child)
		{
			if (child->GetZIndex() < leastOfThese->GetZIndex())
			{
				leastOfThese = child;
			}
			child = child->mpNext;
		}

		if (!sorted)
		{
			InsertFirst(leastOfThese);
		}
		else
		{
			if (sorted->mpNext != leastOfThese)
			{
				InsertAfter(sorted, leastOfThese);
			}
		}

		sorted = unsorted;
		unsorted = unsorted->mpNext;
	}
}
Пример #5
0
void dgBodyMasterList::SortMasterList()
{
	GetFirst()->GetInfo().SortList();

	for (dgListNode* node = GetFirst()->GetNext(); node; ) { 
		node->GetInfo().SortList();
		dgBody* const body1 = node->GetInfo().GetBody();
		
		dgAssert (GetFirst() != node);

		body1->InvalidateCache ();

		dgInt32 key1 = MakeSortMask (body1);
		dgListNode* const entry = node;
		node = node->GetNext();
		dgListNode* prev = entry->GetPrev();
		for (; prev != GetFirst(); prev = prev->GetPrev()) {
			dgBody* const body0 = prev->GetInfo().GetBody();

			dgInt32 key0 = MakeSortMask (body0);
			if (key0 < key1) {
				break;
			}
		}

		if (!prev) {
			dgAssert (entry == GetFirst());
			RotateToBegin (entry);
		} else {
			InsertAfter (prev, entry);
		}
	}

}
Пример #6
0
	void APICALL DOMParserImpl::ParseWithSpecificAction( const char * buffer, sizet bufferLength, eActionType actionType, spINode & node ) {
		auto parsedNode = ParseAsNode( buffer, bufferLength );

		if ( parsedNode ) {
			switch ( actionType ) {
			case kATAppendAsChildren:
				AppendAsChildren( node, parsedNode );
				break;

			case kATReplaceChildren:
				ReplaceChildren( node, parsedNode );
				break;

			case kATAppendOrReplaceChildren:
				AppendOrReplaceChildren( node, parsedNode );
				break;

			case kATInsertBefore:
				InsertBefore( node, parsedNode );
				break;

			case kATInsertAfter:
				InsertAfter( node, parsedNode );
				break;

			case kATReplace:
				ReplaceNode( node, parsedNode );
				break;

			default:
				NOTIFY_ERROR( IError::kEDGeneral, kGECNotImplemented, "Not yet implemented", IError::kESOperationFatal, true, static_cast< sizet >( actionType ) );
			}

		}
	}
Пример #7
0
int main()
{

 struct SLL* head = NULL; //Ek head declare kardiya bas
 InsertEnd(&head,6);
 //DeleteEnd(&head);
 InsertStart(&head,7);
 InsertStart(&head,1);
 InsertEnd(&head,4);
 InsertAfter(head->next,8);

 printList(head);

DeleteEnd(&head);
printf("\n");
printList(head);

DeleteStart(&head);
printf("\n");
printList(head);

DeleteComplete(&head);
printList(head);

  return 0;
}
Пример #8
0
int main(int argc, char **argv)
{
        int i, n;
	scanf("%d", &n);
	struct Elem *nil, *spis;
	nil = InitDoubleLinkedList();
	for(i = 0; i < n; i++) {
		spis = InitDoubleLinkedList();
		scanf("%d", &(spis->v));
		InsertAfter(nil, spis);
	}
	//printf("%d\n", (spis->next)->v);
	InsertSort(nil);
	spis = nil->next;
	struct Elem *help;
	for(i = 0; i < n; i++, spis = spis->next) {
		printf("%d ", spis->v);
		//printf("free %d\n ", (spis->prev)->v);
		if (i)
			free(spis->prev);
	}
        //printf("%d ", (spis->prev)->v);
	printf("\n");
        free(spis->prev);
	free(spis);
	return 0;
}
Пример #9
0
/*CREATE LIST OF TOKENS*/
void Createlist(char *exp,List infix_l)
{
	char p[MAXNAME];	//store var name
	int cnt;		
	

	while((*exp == ' ' || *exp == '\t')  && *exp!='\0')	//remove spaces
		exp++;
	if(*exp=='\'')				//override check eval symbol.
		exp++;
	
	if(*exp == '\0')
		return;
	while(*exp!='\0')			//read till end of line
	{
		while((*exp == ' ' || *exp == '\t') && *exp!='\0')
                exp++;

		if(match_char(*exp)==0)		//if variable
		{
			exp = Extract_word(exp,p);	
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
		}
		else if(match_num(*exp)==0)	//if number
		{
			exp = Extract_num(exp,p);
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
			add_value(p,0,p);
		}
		else if(match_bool(*exp)==0)	//if boolean op
		{
			exp = Extract_bool(exp,p);
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
		}
		else
		{
			p[0] = *exp;		//else single letter operator
			p[1]='\0';
			cnt = Count(infix_l);
			InsertAfter(p,infix_l,cnt);
			exp++;
		}
	}
}
Пример #10
0
template <typename T> const ZsfLinkedListItm<T> *ZsfLinkedList<T>::Add(int index, T *value) {
	if (index) {
		const ZsfLinkedListItm<T> *item = Node(index-1);
		return InsertAfter(item, value);
	} else {
		return AddFirst(value);
	}
}
Пример #11
0
  /**
   * Move this item from its current position in the list after the
   * specified one.
   */
  void MoveAfter(ListHead &other) {
    if (prev == &other) {
      assert(other.next == this);
      return;
    }

    Remove();
    InsertAfter(other);
  }
Пример #12
0
void SimpleList<T>::InsertBefore(SimpleNode<T>* Ptr_, T* NewPtr_)
{
  if (Ptr_ == _List)
    AppendHead(NewPtr_);
  else
  {
    SimpleNode<T>* Node_ = FindPrevious(Ptr_);
    InsertAfter(Node_, NewPtr_);
  }
}
Пример #13
0
void Insert(RBNode** Tree, RBNode* NewNode)
{
	InsertHelp(Tree, NewNode);

	NewNode->Color = Red;
	NewNode->Left = &Nil;
	NewNode->Right = &Nil;

	InsertAfter(Tree, NewNode);
}
Пример #14
0
inline void GAExpressionLib::List< Data, DataManager >::Reverse( void )
{
	if( count > 1 )
	{
		Node* node = head;
		Remove( node, false );
		Reverse();
		InsertAfter( tail, node );
	}
}
Пример #15
0
HEListElm::HEListElm(HTML_Element* inline_elm, InlineResourceType inline_type, FramesDocument* fdoc)
 :   animation_handler(NULL)
   , url_imagecontent_provider(NULL)
   , doc(fdoc)
   , ref(this)
   , image_width(0)
   , image_height(0)
   , image_last_decoded_height(0)
   , inline_type(inline_type)
   , handled(FALSE)
   , syncronize_animation(TRUE)
   , event_sent(FALSE)
#ifdef REMOVE_IRRELEVANT_IMAGES
	, signaled_irrelevant(FALSE)
#endif
   , image_active(TRUE)
#ifdef HAS_ATVEF_SUPPORT
   , is_atvef_image(FALSE)
#endif
   , image_visible(FALSE)
   , delay_load(TRUE)
   , from_user_css(FALSE)
#ifdef CORS_SUPPORT
   , is_crossorigin_allowed(FALSE)
#endif // CORS_SUPPORT
{
	if (inline_elm)
	{
		if (inline_type == EXTRA_BGIMAGE_INLINE)
		{
			// We want to insert the reference after the other bgimages
			// to preserve the sequence instead of first in the list.
			HTML_Element::BgImageIterator iter(inline_elm);
			HEListElm *iter_elm = iter.Next();
			if (iter_elm)
			{
				HEListElm *candidate;
				do
				{
					candidate = iter_elm;
					iter_elm = iter.Next();
				} while (iter_elm);

				InsertAfter(candidate, inline_elm);
			}
			else
				SetElm(inline_elm);
		}
		else
			SetElm(inline_elm);
	}

	if (GetElm()->GetSpecialBoolAttr(ATTR_INLINE_ONLOAD_SENT, SpecialNs::NS_LOGDOC))
		event_sent = TRUE;
}
Пример #16
0
AUI_ERRCODE aui_DirtyList::SubtractRect( RECT *sub )
{
	AUI_ERRCODE alteredList = AUI_ERRCODE_UNHANDLED;

	Assert( sub != NULL );
	if ( !sub ) return alteredList;

	if ( sub->left < sub->right && sub->top < sub->bottom )
	{

		ListPos position = GetHeadPosition();
		for ( sint32 i = L(); i; i-- )
		{
			ListPos prevPosition = position;
			RECT *rect = GetNext( position );

			static RECT moreRects[4];
			static sint32 num;
			if ( (num = Rectangle_Subtract( rect, sub, moreRects )) > 0 )
			{

				if ( memcmp( rect, moreRects, sizeof( RECT ) ) )
				{
					alteredList = AUI_ERRCODE_HANDLED;

					CopyRect( rect, moreRects );

					ListPos insertPosition = prevPosition;
					for ( sint32 j = 1; j < num; j++ )
					{
						RECT *r = m_rectMemory->New();
						Assert( r != NULL );
						if ( !r ) return alteredList;

						CopyRect( r, moreRects + j );

						InsertAfter( insertPosition, r );
						GetNext( insertPosition );
					}
				}
			}
			else if ( !num )
			{
				m_rectMemory->Delete( rect );
				DeleteAt( prevPosition );
			}
			else
			{

			}
		}
	}

	return alteredList;
}
Пример #17
0
  /**
   * Move this item from its current position in the list after the
   * specified one.
   */
  void MoveAfter(ListHead &other) {
    assert(type == CONNECTED);
    assert(other.type == HEAD || other.type == CONNECTED);

    if (prev == &other) {
      assert(other.next == this);
      return;
    }

    Remove();
    InsertAfter(other);
  }
Пример #18
0
inline void GAExpressionLib::List< Data, DataManager >::CopyAfter( Node* node, const List* list )
{
	if( !node )
		node = tail;

	if( node && node->list != this )
		return;

	for( const Node* otherNode = list->head; otherNode; otherNode = otherNode->Next() )
	{
		node = InsertAfter( node );
		DataManager::Copy( node->data, otherNode->data );
	}
}
Пример #19
0
int main(void) {
    int choice = 0, loopflag = 1;
    char NewData[255], OldData[255];
    printf("原串列 :\n");
    PrintList(table);

    while (loopflag) {
        printf("(1)插入節點,(2)刪除節點, (其它鍵) 離開 =>");
        scanf("%d", &choice);

        switch (choice) {
        case 1:
            printf("\n請輸入欲插入之資料=>");
            scanf("%s", NewData);
            strupr(NewData);
            printf("請輸入欲插入那一資料之後 ( 輸入HEAD代表成為第一個資料 ) =>");
            scanf("%s", OldData);
            strupr(OldData);

            if (InsertAfter(table, OldData, NewData) == FALSE) {
                printf("插入失敗\n");
                break;
            }

            printf("插入 %s 之後的串列 :\n", NewData);
            PrintList(table);
            break;

        case 2:
            printf("\n請輸入欲刪除那一資料=>");
            scanf("%s", OldData);
            strupr(OldData);

            if (ListDelete(table, OldData) == FALSE) {
                printf("找不到資料,刪除失敗\n");
                break;
            }

            printf("刪除 %s 之後的串列 :\n", OldData);
            PrintList(table);
            break;

        default:
            loopflag = 0;
        }
    }

    return 0;
}
Пример #20
0
void dgBodyMasterList::AddBody (dgBody* const body)
{
	dgListNode* const node = Append();
	body->m_masterNode = node;
	node->GetInfo().SetAllocator (body->GetWorld()->GetAllocator());
	node->GetInfo().m_body = body;

	if (GetFirst() != node) {
		InsertAfter (GetFirst(), node);
	}

	if (body->IsRTTIType(dgBody::m_deformableBodyRTTI)) {
		m_deformableCount ++;
	}
}
Пример #21
0
inline void GAExpressionLib::List< Data, DataManager >::AbsorbAfter( Node* node, List* list )
{
	if( !node )
		node = tail;

	if( node && node->list != this )
		return;

	while( list->count > 0 )
	{
		Node* otherNode = list->head;
		list->Remove( otherNode, false );
		node = InsertAfter( node, otherNode );
	}
}
Пример #22
0
LIterator LStrList::InsertAfter(__in LIterator it, __in PCWSTR lpString)
{
    LIterator ret = NULL;
    LAutoLock al(m_lock);
    if (IsUnicode())
    {
        ret = LPtrList::InsertAfter(it, &lpString);
    }
    else
    {
        LStringA str = lpString;
        ret = InsertAfter(it, str);
    }
    return ret;
}
Пример #23
0
/*void ListSearch(struct Elem *spis, struct Elem *spis1, struct Elem *spis2)
{
	while ((spis2 != spis) && (spis1->v < spis2->v))
		spis2 = spis2->prev;
} */
void InsertSort(struct Elem *spis)
{
	struct Elem *spis1, *spis2;
	spis1 = (spis->next)->next;
	//printf("%d\n", spis1->v);
	while (spis1 != spis) {
		spis2 = spis1->prev;
		//ListSearch(spis, spis1, spis2);
		while ((spis2 != spis) && (spis1->v < spis2->v))
			spis2 = spis2->prev;
		//printf("%d - %d\n", spis2->v, spis1->v);
		Delete(spis1);
		InsertAfter(spis2, spis1);
		spis1 = spis1->next;
	}
}
Пример #24
0
void InsertLast(List *L, addressList P)
/* I.S. Sembarang, P sudah dialokasi */
/* F.S. P ditambahkan sebagai elemen terakhir yang baru */
{
    if (IsEmptyList(*L))
    {
        InsertFirst(L, P);
    }
    else
    {
        addressList Last = First(*L);
        while (Next(Last) != NULL)
            Last = Next(Last);
        InsertAfter(L, P, Last);
    }
}
Пример #25
0
void dgBodyMasterListRow::SortList()
{
	for (dgListNode* node = GetFirst(); node; ) { 

		dgListNode* const entry = node;
		node = node->GetNext();
		dgListNode* prev = entry->GetPrev();
		for (; prev; prev = prev->GetPrev()) {
			if (prev < entry) {
				break;
			}
		}

		if (!prev) {
			RotateToBegin (entry);
		} else {
			InsertAfter (prev, entry);
		}
	}
}
Пример #26
0
void DisplayElement::InsertOrdered (DisplayElement *pChild)
{
DisplayElement *place = mpLastChild;
long zIndex = pChild->GetZIndex();

	while (place)
	{
		if (place->GetZIndex() <= zIndex)
		{
			// check to make sure we aren't trying to insert child after itself
			if (place != pChild)
			{
				InsertAfter(place, pChild);
			}
			return;
		}
		place = place->mpPrev;
	}

	InsertFirst(pChild);
}
Пример #27
0
LISTPOS OverrideList::InsertAfter(LISTPOS here, OverrideListItem* item)
{
	ERROR2IF(item==NULL, 0, "OverrideList::InsertAfter - NULL parameter");

	//First find the list item at the position we have been given
	OverrideListItem* pliInsertionPoint=(OverrideListItem*) FindItem(here);

	//If we have not found it, return -1
	if (pliInsertionPoint==NULL)
		return -1;

	//Otherwise, call our other function to do the insertion
	OverrideListItem* pliResult=(OverrideListItem*) InsertAfter(pliInsertionPoint, item);

	//If we have been returned NULL, then return an error value
	if (pliResult==NULL)
		return -1;

	//Otherwise, find our newly returned list item in the list
	//and return it
	return FindPosition(pliResult);
	
}
Пример #28
0
//---------------------------------------------------------------------------
inline void LinkedList::MoveAfter (Link *PlaceTo, Link *NodeToPut, Link *Last)
{
	Remove (NodeToPut, Last);
	InsertAfter (PlaceTo, NodeToPut);
}
Пример #29
0
void main(void) {
    int choose, i, insertdata, num;
    DListNode* p;
    DListNode* listA;
    FILE* fin;
    listA = (DListNode*)malloc(sizeof(DListNode));
    listA->left = listA;
    listA->right = listA;
    p = listA;

    if ((fin = fopen("List.in", "r")) == NULL) {
        printf("開檔失敗,結束程式 (File can not be opened, program terminate.)");
    } else {
        fscanf(fin, "%d", &insertdata);

        while (!feof(fin)) {
            InsertAfter(p, insertdata);
            p = p->right;
            fscanf(fin, "%d", &insertdata);
        }

        fclose(fin);

        while (1) {
            printf("\n環狀雙向鏈結串列內容( Content of circular doubly linked list )=>\n");
            PrintList(listA);
            printf("\n(1)附加節點(Append new node)\n(2)插入節點(Insert new node)\n(3)刪除節點(Delete node)\n(0)結束(exit)=>");
            scanf("%d", &choose);

            switch (choose) {
            case 0:
                FreeAllNode(listA);     /*釋放所有節點*/
                exit(0);            /*結束程式*/

            case 1:
                printf("請輸入欲附加之資料(Input new data )=>");
                scanf("%d", &insertdata);

                for (p = listA; p->right != listA; p = p->right);

                InsertAfter(p, insertdata);
                break;

            case 2:
                printf("請輸入欲插入之資料(Input new data )=>");
                scanf("%d", &insertdata);
                printf("請輸入欲插入之位置(New Position)=>");
                scanf("%d", &num);

                for (i = 1, p = listA; i != num && p->right != listA; p = p->right, i++);

                if (p == NULL) {
                    printf("插入失敗( Insert Failed )");
                } else if (InsertAfter(p, insertdata) == 0) {
                    printf("插入失敗( Insert Failed )");
                }

                break;

            case 3:
                printf("請輸入欲刪除之資料 ( data to be deleted )=>");
                scanf("%d", &num);

                for (i = 0, p = listA->right; p != listA && p->data != num ; p = p->right, i++);

                if (p == listA) {
                    printf("此資料不在串列中( the data is not in list )");
                } else if (DeleteNode(p) == 0) {
                    printf("刪除失敗( Delete Failed)");
                }

                break;

            default:
                printf("選項錯誤 ( Wrong option )");
            }
        }
    }
}
Пример #30
0
int main()
{
	/* Kamus Lokal */
		List MyList, List2, List3;
		int i;
		infotype isi;
		address P, Prec;
		
	/* Program */
	CreateList (&MyList);
	printf ("Jml Elemen List adalah : %d \n", NbElmt(MyList));
/* Menambah List di awal */
	i = 1;
	while (i <= 5)
	{
		InsVFirst (&MyList, i*5);
		i++;
	}
	printf ("Hasil InsVFirst 5 x adalah : "); PrintInfo (MyList);
	printf ("Node Maksimal = %d ",Max (MyList));
	printf ("Node Minimal = %d ",Min (MyList));
	printf ("Rata-rata = %d \n",Average (MyList));
/* Mencari suatu elemen di list */	

	P = Search(MyList, 15);
printf ("Search yang berhasil (15) : P = %d, Ketemu = %d \n",P,FSearch(MyList,P));
	DelP (&MyList, 15);

/* Insert di Last */
	printf ("Insert di akhir nilai 723 : ");
	InsVLast (&MyList, 723); 
	PrintInfo (MyList);

/* Insert diantara 2 elemen */
	printf ("Insert sebelum elemen 10  : ");
	Prec = SearchPrec (MyList, 10);
	P = Alokasi (2712);
	if (P != Nil)
	{   InsertAfter (&MyList, P, Prec);	}
	PrintInfo (MyList);
	
/* Menghapus elemen List */	
	printf ("\tHasil Delete dari elemen List :\n");
	printf ("Jumlah elemen list = %d \n", NbElmt(MyList));
	DelVFirst (&MyList, &isi);		
	printf ("DelVFirst adalah %d\t", isi);
	
	DelVLast (&MyList, &isi);		
	printf ("DelVLast adalah %d\t", isi);

/* Menghapus elemen di tengah-tengah */
	Prec = SearchPrec (MyList, 10);	/* Node yang akan dihapus */
	if (Prec != Nil)
	{
	    DelAfter (&MyList, &P, Prec);		
	    isi = Info(P);
	    DeAlokasi (P);
	    printf ("DelAfter adalah %d\n", isi);
	}    
	printf ("Hasil setelah delete : ");
        PrintInfo (MyList);
	
	printf ("Insert sebelum elemen 5 : ");
	Prec = SearchPrec (MyList, 5);
	P = Alokasi (-987);
	if (P != Nil)
	{   InsertAfter (&MyList, P, Prec);	}
	PrintInfo (MyList);

/* Invers List */
	printf ("\tHasil Invers dari List yang ada : \n");
	printf ("Versi 1 : ");
	List2 = FInversList (MyList);	
	PrintInfo (List2);
	
	printf ("Versi 2 : ");
	InversList (&MyList);
        PrintInfo (MyList);

/* Copy List */
	printf ("\tHasil Copy dari List yang ada : \n");
	printf("Versi 1 : ");
	CopyList (MyList, &List2);
	PrintInfo (List2);	

	printf ("Versi 2 : ");
	List3 = FCopyList (MyList);
	PrintInfo (List3);	
	
	printf ("Versi 3 : ");
	CpAlokList (MyList, &List2);
	PrintInfo (List2);	

/* Konkat */ 
	printf("\tHasil Konkat Invers dan List asli : \n");
	List2 = FInversList (MyList);	
	Konkat (List2, List3, &MyList);
	printf("Versi 1 : ");
	PrintInfo (MyList);	

	Konkat1 (&List2, &List3, &MyList);
	printf("Versi 2 : ");
	PrintInfo (MyList);	

/* Pecah List */
	PecahList (&List2, &List3, MyList);
	printf ("\tHasil membagi dua list adalah : \n");
	printf ("L1 = "); PrintInfo (List2);
	printf ("L2 = "); PrintInfo (List3);
/* Finishing */	
	P = First(MyList);
	DeAlokasi (P); 
	P = First(List2);
	DeAlokasi (P); 
	P = First(List3);
	DeAlokasi (P); 
	return 0;
}