-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListFunc.h
More file actions
85 lines (72 loc) · 1.77 KB
/
ListFunc.h
File metadata and controls
85 lines (72 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <iostream>
#include <math.h>
#include <vector>
#include <queue>
//#include <priority_queue>
using namespace std;
typedef struct Node
{
friend bool operator<(const Node &pnode1, const Node &pnode2)
{
return pnode1.nValue > pnode2.nValue;
}
int nValue;
Node* pNext;
Node(int _value):nValue(_value),pNext(nullptr){}
}NODE,*PNODE;
class SingleList
{
public:
SingleList(void);
~SingleList(void);
public:
void InsertTail(int nvalue);
void InsertHead(int nvalue);
bool InsertElementPos(int nvalue, int nPos);
bool Delete(int nValue);
PNODE Reverse(PNODE pHead);
PNODE Reverse_no(PNODE pHead);
void DeleteAll(PNODE pHead);
PNODE ReverseBetween(PNODE pHead, int nStart, int nEnd);
void Print(PNODE pHead);
PNODE MergeKLists(vector<PNODE>& lists); //23题
PNODE MergeTwoLists(PNODE l1, PNODE l2); //21题
PNODE SortList(PNODE pHead); //146题 ---在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序。
PNODE InsertSortList(PNODE pHead); //147题 对链表进行插入排序
//
PNODE reverseKGroup(PNODE pHead, int k); //25题
public:
void TestSingleList();
protected:
PNODE Cut(PNODE pHead, int nSize);
int GetListLen(PNODE pHead);
private:
PNODE m_pHead;
};
//////////////////////////////////////////////////////////////////////////
typedef struct DNode
{
int val;
DNode* pPre;
DNode* pNext;
DNode(int nvalue):val(nvalue),pPre(nullptr),pNext(nullptr){}
}DNODE,*PDNODE;
class DoubleList
{
public:
DoubleList(void);
~DoubleList(void);
public:
void InsertTail(int nvalue);
void InsertHead(int nvalue);
int InsertElementPos(int nvalue, int nPos);
bool DeleteElement(int nvalue);
void DeleteAll(PDNODE pHead);
PDNODE Reverse(PDNODE pHead);
void PrePrint(PDNODE pHead);
void PostPrint(PDNODE pTail);
protected:
private:
PDNODE m_pHead;
};