Пример #1
0
int removeLLElement(LinkedList* pList, int position)
{
	int ret = FALSE;
	int i = 0;
	int arrayCount = 0;
	ListNode* pNode = NULL;
	ListNode* pDelNode = NULL;
	if (pList != NULL) {
		arrayCount = getLinkedListLength(pList);
		if (position >=0 && position < arrayCount)
		{
			pNode = &(pList->headerNode);
			for(i = 0; i < position; i++) {
				pNode = pNode->pLink;
			}

			pDelNode = pNode->pLink;
			pNode->pLink = pDelNode->pLink;
			free(pDelNode);

			pList->currentElementCount--;
			ret = TRUE;
		}
		else {
			printf("오류, 위치 인덱스-[%d] removeLLElement()\n", position);
		}
	}

	return ret;
}
Пример #2
0
 ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2) {
     if (pHead1 == NULL || pHead2 == NULL) return NULL;
     int len_01 = getLinkedListLength(pHead1);
     int len_02 = getLinkedListLength(pHead2);
     ListNode* p_1 = pHead1;
     ListNode* p_2 = pHead2;
     int len;
     if (len_01 > len_02) len = len_01 - len_02; 
     else if (len_01 < len_02) {
         len = len_02 - len_01;
         p_1 = pHead2;
         p_2 = pHead1;
     }
     while (len > 0) {
         p_1 = p_1->next;
         len--;
     }
     while ((p_1 != p_2) && (p_1 != NULL && p_2 != NULL)) {
         p_1 = p_1->next;
         p_2 = p_2->next;
     }
     return p_1;
 }