Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tree.cpp #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions 18_02_DeleteDuplicatedNode/DeleteDuplicatedNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Distributed under the BSD license.
*******************************************************************/

//==================================================================
// ����ָOffer�����������Թپ������ͱ���⡷����
// ���ߣ��κ���
// 《剑指Offer——名企面试官精讲典型编程题》代码
// 作者:何海涛
//==================================================================

// ������18��������ɾ���������ظ��Ľ��
// ��Ŀ����һ������������У����ɾ���ظ��Ľ�㣿���磬��ͼ3.4��a�����ظ�
// ��㱻ɾ��֮��������ͼ3.4��b����ʾ��
// 面试题18(二):删除链表中重复的结点
// 题目:在一个排序的链表中,如何删除重复的结点?例如,在图3.4(a)中重复
// 结点被删除之后,链表如图3.4(b)所示。

#include <cstdio>
#include "../Utilities/list.h"
Expand Down Expand Up @@ -47,7 +47,6 @@ void DeleteDuplication(ListNode** pHead)
pNext = pToBeDel->m_pNext;

delete pToBeDel;
pToBeDel = nullptr;

pToBeDel = pNext;
}
Expand All @@ -61,7 +60,7 @@ void DeleteDuplication(ListNode** pHead)
}
}

// ====================���Դ���====================
// ====================测试代码====================
void Test(char* testName, ListNode** pHead, int* expectedValues, int expectedLength)
{
if(testName != nullptr)
Expand All @@ -86,7 +85,7 @@ void Test(char* testName, ListNode** pHead, int* expectedValues, int expectedLen
printf("FAILED.\n");
}

// ijЩ������ظ���
// 某些结点是重复的
void Test1()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -112,7 +111,7 @@ void Test1()
DestroyList(pHead);
}

// û���ظ��Ľ��
// 没有重复的结点
void Test2()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -138,7 +137,7 @@ void Test2()
DestroyList(pHead);
}

// ����һ�����֮���������н���ֵ����ͬ
// 除了一个结点之外其他所有结点的值都相同
void Test3()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -164,7 +163,7 @@ void Test3()
DestroyList(pHead);
}

// ���н���ֵ����ͬ
// 所有结点的值都相同
void Test4()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -189,7 +188,7 @@ void Test4()
DestroyList(pHead);
}

// ���н�㶼�ɶԳ���
// 所有结点都成对出现
void Test5()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -216,7 +215,7 @@ void Test5()
DestroyList(pHead);
}

// �����������֮��������㶼�ɶԳ���
// 除了两个结点之外其他结点都成对出现
void Test6()
{
ListNode* pNode1 = CreateListNode(1);
Expand Down Expand Up @@ -244,7 +243,7 @@ void Test6()
DestroyList(pHead);
}

// ������ֻ���������ظ��Ľ��
// 链表中只有两个不重复的结点
void Test7()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -260,7 +259,7 @@ void Test7()
DestroyList(pHead);
}

// �����ֻ��һ�����
// 结点中只有一个结点
void Test8()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -275,7 +274,7 @@ void Test8()
DestroyList(pHead);
}

// �����ֻ�������ظ��Ľ��
// 结点中只有两个重复的结点
void Test9()
{
ListNode* pNode1 = CreateListNode(1);
Expand All @@ -290,7 +289,7 @@ void Test9()
DestroyList(pHead);
}

// ������
// 空链表
void Test10()
{
ListNode* pHead = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions Utilities/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ Distributed under the BSD license.
*******************************************************************/

//==================================================================
// ����ָOffer�����������Թپ������ͱ���⡷����
// ���ߣ��κ���
// 《剑指Offer——名企面试官精讲典型编程题》代码
// 作者:何海涛
//==================================================================

#include "Tree.h"
Expand Down Expand Up @@ -42,6 +42,7 @@ void PrintTreeNode(const TreeNode* pNode)
{
if(*i != nullptr)
printf("%d\t", (*i)->m_nValue);
++i;
}

printf("\n");
Expand Down