예제 #1
0
// 测试空链表
void Test4()
{
    printf("=====Test4 starts:=====\n");
    printf("expected result: NULL.\n");
    ListNode* pNode = FindKthToTail(NULL, 100);
    PrintListNode(pNode);
}
예제 #2
0
int main(void)
{
	pNode pHead = (pNode)malloc(sizeof(Node));
	pHead = CreatList();
	printf("%d", FindKthToTail(pHead,3));
	/*TraverseList(pHead);*/
	return 0;
}
예제 #3
0
void Test1()
{
    ListNode* pNode1 = CreateListNode(1);
    ListNode* pNode2 = CreateListNode(2);
    ListNode* pNode3 = CreateListNode(3);
    ListNode* pNode4 = CreateListNode(4);
    ListNode* pNode5 = CreateListNode(5);

    ConnectListNodes(pNode1, pNode2);
    ConnectListNodes(pNode2, pNode3);
    ConnectListNodes(pNode3, pNode4);
    ConnectListNodes(pNode4, pNode5);

    printf("Expected result: 4 \n");
    ListNode* pNode = FindKthToTail(pNode1, 2);
    PrintListNode(pNode);

    DestroyList(pNode1);
}
예제 #4
0
// 测试要找的结点是链表的头结点
void Test3()
{
    printf("=====Test3 starts:=====\n");
    ListNode* pNode1 = CreateListNode(1);
    ListNode* pNode2 = CreateListNode(2);
    ListNode* pNode3 = CreateListNode(3);
    ListNode* pNode4 = CreateListNode(4);
    ListNode* pNode5 = CreateListNode(5);

    ConnectListNodes(pNode1, pNode2);
    ConnectListNodes(pNode2, pNode3);
    ConnectListNodes(pNode3, pNode4);
    ConnectListNodes(pNode4, pNode5);

    printf("expected result: 1.\n");
    ListNode* pNode = FindKthToTail(pNode1, 5);
    PrintListNode(pNode);

    DestroyList(pNode1);
}
예제 #5
0
int _tmain(int argc, _TCHAR* argv[])
{
	//print1ToMaxOfNDigits(10);
	
	int arr[16];
	srand((unsigned int)time(NULL));
	for (int i=0;i<16;i++)
	{
		arr[i] = rand()%100;
		std::cout << arr[i] << " ";
	}
	std::cout << std::endl;
	ReorderOddEven(arr,16,IsEven);
	for (int i=0;i<16;i++)
	{
		std::cout << arr[i] << " ";
	}


	LinkNode *pHead = new LinkNode;
	pHead->value = 0;
	pHead->next = NULL;
	for (int i=1;i<10000;i++)
	{
		LinkNode *node = new LinkNode;
		node->value = i;
		node->next = pHead->next;
		pHead->next = node;
	}
	std::cout <<std::endl<< FindKthToTail(pHead,4000)->value << std::endl;
	while (pHead->next!=NULL)
	{
		LinkNode *node = pHead->next;
		pHead->next = node->next;
		delete node;
	}
	
	return 0;
}