Пример #1
0
	FPTRLIST_INLINE bool FPtrList::FPtrListPrivate::insert(int nIndex, LPVOID pVal)
	{
		if (nIndex == 0)
		{
			return addToHeader(pVal);
		}
		else if (nIndex == m_nSize)
		{
			return addToLast(pVal);
		}
		
		if (!moveTo(nIndex)) return false;
		FASSERT(NULL != m_pCursor);

		FPtrList::FPtrListPrivate::FPTRLIST_NODE *pNode = new FPtrList::FPtrListPrivate::FPTRLIST_NODE;
		pNode->pPrevious = m_pCursor->pPrevious;
		pNode->pNext = m_pCursor;
		pNode->pList = this;
		pNode->pVal = pVal;

		m_pCursor->pPrevious->pNext = pNode;
		m_pCursor->pPrevious = pNode;

		m_nSize++;

		moveToHeader();

		return true;
	}
Пример #2
0
int main(){
	Node *head1,*head2,*result;
	head1=head2=result=NULL;
	int a1[]={9,9,9};
	int a2[]={1,8};
	int n1,n2,i;
	n1=sizeof(a1)/sizeof(a1[0]);
	n2=sizeof(a2)/sizeof(a2[0]);
	for(i=0;i<n1;i++)
		head1=addToLast(head1,a1[i]);
	for(i=0;i<n2;i++)
		head2=addToLast(head2,a2[i]);
	printf("\nList 1 is:");
	printList(head1);
	printf("\nList 2 is:");
	printList(head2);
	add(head1,head2,&result);
	printf("\nResult is:");
	printList(result);
	printf("\n");
	return 0;	
}
Пример #3
0
int main(){

	struct node *root = (struct node *) malloc(sizeof(struct node));
	struct node *first = (struct node *) malloc(sizeof(struct node));
	
	root->next = first;
	
	first->next = NULL;
	first->data = 10;
	printf("First List\n");
	printList(root->next);
	
	struct node *second = (struct node *) malloc(sizeof(struct node));
	second->data = 5;
	addToFront(second, root);
	printf("Second List\n");
	printList(root->next);
	
	struct node *third = (struct node *) malloc(sizeof(struct node));
	third->data = 15;
	addToLast(third, root);
	printf("Third List\n");
	printList(root->next);
	
	struct node *mid = (struct node *) malloc(sizeof(struct node));
	mid->data = 12;
	addAt(mid, first);
	printf("Fourth List\n");
	printList(root->next);
	
	struct node *mid2 = (struct node *) malloc(sizeof(struct node));
	mid2->data = 14;
	addAt(mid2, mid);
	printf("Fifth List\n");
	printList(root->next);
	
	deleteNode(mid2, root);
	printf("Sixth List\n");
	printList(root->next);
	
	return 0;
}
Пример #4
0
	FPTRLIST_INLINE bool FPtrList::FPtrListPrivate::add(LPVOID pVal)
	{
		return addToLast(pVal);
	}