Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8be328f

Browse files
author
junl
committed
修改部分文档
1 parent fe41b12 commit 8be328f

File tree

22 files changed

+1425
-128
lines changed

22 files changed

+1425
-128
lines changed

‎ADT/main.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// main.cpp
3+
// ADT
4+
//
5+
// Created by junl on 2020年7月14日.
6+
// Copyright © 2020 junl. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
#include "max_priority_queue.h"
11+
int main(int argc, const char * argv[]) {
12+
// insert code here...
13+
std::cout << "Hello, World!\n";
14+
max_priority_queue queue(4);
15+
queue.insert(1);
16+
printf("max = %d\n", queue.max());
17+
queue.insert(7);
18+
printf("max = %d\n", queue.max());
19+
queue.insert(3);
20+
printf("max = %d\n", queue.max());
21+
queue.insert(5);
22+
printf("max = %d\n", queue.max());
23+
int v ;
24+
v = queue.remove_max();
25+
printf("before max = %d, now max = %d\n",v, queue.max());
26+
v = queue.remove_max();
27+
printf("before max = %d, now max = %d\n",v, queue.max());
28+
v = queue.remove_max();
29+
printf("before max = %d, now max = %d\n",v, queue.max());
30+
return 0;
31+
}

‎ADT/max_priority_queue.h‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// max_priority_queue.h
3+
// ADT
4+
//
5+
// Created by junl on 2020年7月14日.
6+
// Copyright © 2020 junl. All rights reserved.
7+
//
8+
9+
#ifndef max_priority_queue_h
10+
#define max_priority_queue_h
11+
12+
/*
13+
优先级队列是基于二叉堆来实现的。 二叉堆是什么? 它是一种特殊的二叉树(完全二叉树),只不过一般存储在数组里面.
14+
二叉堆有大顶堆和小顶堆. 大顶堆就是说根节点比子节点都大,这对应到优先级队列就是arr[1] 一定是所有元素中最大的元素. 小顶堆同理.
15+
16+
要维持二叉堆的这样结构,我们需要sink下沉和上浮swim操作,它们的目的是为了维护二叉堆的结构.
17+
*/
18+
class max_priority_queue{
19+
public:
20+
max_priority_queue(int cap){
21+
this->cap = cap;
22+
this->cnt = 0;
23+
this->elements = new int[cap+1];//下标0不使用
24+
}
25+
void insert(int val){
26+
if (cnt >= cap) return;
27+
elements[++cnt] = val;
28+
swim(cnt);
29+
}
30+
int remove_max(){
31+
if (cnt == 0) return -1;
32+
int max = elements[1];
33+
std::swap(elements[1], elements[cnt]);
34+
cnt--;
35+
sink(1);
36+
return max;
37+
}
38+
int max(){
39+
if (cnt == 0) return -1;
40+
return elements[1];
41+
}
42+
private:
43+
//获取左节点下标
44+
int left(int idx){
45+
return 2 * idx;
46+
}
47+
//获取右节点下标
48+
int right(int idx){
49+
return 2 * idx + 1;
50+
}
51+
int parent(int idx){
52+
return idx / 2;
53+
}
54+
//下沉操作
55+
void sink(int idx){
56+
int leftidx;
57+
while ((leftidx = left(idx)) < cnt) {
58+
//获取左右节点中的最大值
59+
if (leftidx+1 < cnt && elements[leftidx] < elements[leftidx+1])
60+
leftidx++;
61+
if (elements[leftidx] <= elements[idx])
62+
break;
63+
std::swap(elements[idx], elements[leftidx]);
64+
idx = leftidx;
65+
}
66+
}
67+
//上浮操作
68+
void swim(int idx){
69+
int parentidx;
70+
while((parentidx = parent(idx)) >= 1 && elements[idx] > elements[parentidx]){
71+
std::swap(elements[idx], elements[parentidx]);
72+
idx = parentidx;
73+
}
74+
}
75+
int cap;//容量
76+
int cnt;//当前数据个数
77+
int *elements;//存储地址
78+
};
79+
80+
#endif /* max_priority_queue_h */

‎alg-cpp.xcodeproj/project.pbxproj‎

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
0946B04822F6D3890043469D /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0946B04722F6D3890043469D /* main.cpp */; };
1212
0969A71E22E607E800CA9347 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0969A71D22E607E800CA9347 /* main.cpp */; };
1313
0998EB8D22E75FB9005A01B5 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0998EB8C22E75FB9005A01B5 /* main.cpp */; };
14+
09A05C7B24BE09EF0010C78B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09A05C7A24BE09EF0010C78B /* main.cpp */; };
1415
09ACF02E2316DB0B004A4A61 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09ACF02D2316DB0B004A4A61 /* main.cpp */; };
1516
09CE1EBD23269D4200001ECB /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09CE1EBC23269D4200001ECB /* main.cpp */; };
1617
3A5C8B8E22E0103B00354740 /* LRUV2.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A5C8B8C22E0103B00354740 /* LRUV2.h */; };
@@ -70,6 +71,15 @@
7071
);
7172
runOnlyForDeploymentPostprocessing = 1;
7273
};
74+
09A05C7624BE09EF0010C78B /* CopyFiles */ = {
75+
isa = PBXCopyFilesBuildPhase;
76+
buildActionMask = 2147483647;
77+
dstPath = /usr/share/man/man1/;
78+
dstSubfolderSpec = 0;
79+
files = (
80+
);
81+
runOnlyForDeploymentPostprocessing = 1;
82+
};
7383
09ACF0292316DB0B004A4A61 /* CopyFiles */ = {
7484
isa = PBXCopyFilesBuildPhase;
7585
buildActionMask = 2147483647;
@@ -269,6 +279,9 @@
269279
099EAEF022FFB55A006437BD /* MinStack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MinStack.h; sourceTree = "<group>"; };
270280
099EAEF522FFBED0006437BD /* reverse_integer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = reverse_integer.h; sourceTree = "<group>"; };
271281
099EAEF822FFC4C5006437BD /* palindrome_number.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = palindrome_number.h; sourceTree = "<group>"; };
282+
09A05C7824BE09EF0010C78B /* ADT */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ADT; sourceTree = BUILT_PRODUCTS_DIR; };
283+
09A05C7A24BE09EF0010C78B /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
284+
09A05C7F24BE0A420010C78B /* max_priority_queue.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = max_priority_queue.h; sourceTree = "<group>"; };
272285
09A208B02308D96E00094088 /* zigzag_conversion.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = zigzag_conversion.h; sourceTree = "<group>"; };
273286
09A208B32309990C00094088 /* string_to_integer_atoi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = string_to_integer_atoi.h; sourceTree = "<group>"; };
274287
09A3F5C2237A358600BE6839 /* copyListWithRand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = copyListWithRand.h; sourceTree = "<group>"; };
@@ -443,6 +456,13 @@
443456
);
444457
runOnlyForDeploymentPostprocessing = 0;
445458
};
459+
09A05C7524BE09EF0010C78B /* Frameworks */ = {
460+
isa = PBXFrameworksBuildPhase;
461+
buildActionMask = 2147483647;
462+
files = (
463+
);
464+
runOnlyForDeploymentPostprocessing = 0;
465+
};
446466
09ACF0282316DB0B004A4A61 /* Frameworks */ = {
447467
isa = PBXFrameworksBuildPhase;
448468
buildActionMask = 2147483647;
@@ -804,6 +824,15 @@
804824
path = easy;
805825
sourceTree = "<group>";
806826
};
827+
09A05C7924BE09EF0010C78B /* ADT */ = {
828+
isa = PBXGroup;
829+
children = (
830+
09A05C7A24BE09EF0010C78B /* main.cpp */,
831+
09A05C7F24BE0A420010C78B /* max_priority_queue.h */,
832+
);
833+
path = ADT;
834+
sourceTree = "<group>";
835+
};
807836
09ABED862300EDFE00113589 /* leetcode */ = {
808837
isa = PBXGroup;
809838
children = (
@@ -1049,6 +1078,7 @@
10491078
0946B04622F6D3880043469D /* other */,
10501079
09ACF02C2316DB0B004A4A61 /* divideandconquer */,
10511080
09CE1EBB23269D4200001ECB /* greed */,
1081+
09A05C7924BE09EF0010C78B /* ADT */,
10521082
3A717D6922DEBC4E002DA2C2 /* Products */,
10531083
3A717D8F22DEBECF002DA2C2 /* Frameworks */,
10541084
);
@@ -1073,6 +1103,7 @@
10731103
0946B04522F6D3880043469D /* other */,
10741104
09ACF02B2316DB0B004A4A61 /* divideandconquer */,
10751105
09CE1EBA23269D4200001ECB /* greed */,
1106+
09A05C7824BE09EF0010C78B /* ADT */,
10761107
);
10771108
name = Products;
10781109
sourceTree = "<group>";
@@ -1301,6 +1332,23 @@
13011332
productReference = 0998EB8A22E75FB9005A01B5 /* dp */;
13021333
productType = "com.apple.product-type.tool";
13031334
};
1335+
09A05C7724BE09EF0010C78B /* ADT */ = {
1336+
isa = PBXNativeTarget;
1337+
buildConfigurationList = 09A05C7E24BE09EF0010C78B /* Build configuration list for PBXNativeTarget "ADT" */;
1338+
buildPhases = (
1339+
09A05C7424BE09EF0010C78B /* Sources */,
1340+
09A05C7524BE09EF0010C78B /* Frameworks */,
1341+
09A05C7624BE09EF0010C78B /* CopyFiles */,
1342+
);
1343+
buildRules = (
1344+
);
1345+
dependencies = (
1346+
);
1347+
name = ADT;
1348+
productName = ADT;
1349+
productReference = 09A05C7824BE09EF0010C78B /* ADT */;
1350+
productType = "com.apple.product-type.tool";
1351+
};
13041352
09ACF02A2316DB0B004A4A61 /* divideandconquer */ = {
13051353
isa = PBXNativeTarget;
13061354
buildConfigurationList = 09ACF02F2316DB0B004A4A61 /* Build configuration list for PBXNativeTarget "divideandconquer" */;
@@ -1526,6 +1574,9 @@
15261574
0998EB8922E75FB9005A01B5 = {
15271575
CreatedOnToolsVersion = 10.2.1;
15281576
};
1577+
09A05C7724BE09EF0010C78B = {
1578+
CreatedOnToolsVersion = 10.3;
1579+
};
15291580
09ACF02A2316DB0B004A4A61 = {
15301581
CreatedOnToolsVersion = 10.3;
15311582
};
@@ -1592,6 +1643,7 @@
15921643
0946B04422F6D3880043469D /* other */,
15931644
09ACF02A2316DB0B004A4A61 /* divideandconquer */,
15941645
09CE1EB923269D4200001ECB /* greed */,
1646+
09A05C7724BE09EF0010C78B /* ADT */,
15951647
);
15961648
};
15971649
/* End PBXProject section */
@@ -1629,6 +1681,14 @@
16291681
);
16301682
runOnlyForDeploymentPostprocessing = 0;
16311683
};
1684+
09A05C7424BE09EF0010C78B /* Sources */ = {
1685+
isa = PBXSourcesBuildPhase;
1686+
buildActionMask = 2147483647;
1687+
files = (
1688+
09A05C7B24BE09EF0010C78B /* main.cpp in Sources */,
1689+
);
1690+
runOnlyForDeploymentPostprocessing = 0;
1691+
};
16321692
09ACF0272316DB0B004A4A61 /* Sources */ = {
16331693
isa = PBXSourcesBuildPhase;
16341694
buildActionMask = 2147483647;
@@ -1812,6 +1872,26 @@
18121872
};
18131873
name = Release;
18141874
};
1875+
09A05C7C24BE09EF0010C78B /* Debug */ = {
1876+
isa = XCBuildConfiguration;
1877+
buildSettings = {
1878+
CODE_SIGN_STYLE = Automatic;
1879+
DEVELOPMENT_TEAM = K78T9LD5UA;
1880+
MACOSX_DEPLOYMENT_TARGET = 10.14;
1881+
PRODUCT_NAME = "$(TARGET_NAME)";
1882+
};
1883+
name = Debug;
1884+
};
1885+
09A05C7D24BE09EF0010C78B /* Release */ = {
1886+
isa = XCBuildConfiguration;
1887+
buildSettings = {
1888+
CODE_SIGN_STYLE = Automatic;
1889+
DEVELOPMENT_TEAM = K78T9LD5UA;
1890+
MACOSX_DEPLOYMENT_TARGET = 10.14;
1891+
PRODUCT_NAME = "$(TARGET_NAME)";
1892+
};
1893+
name = Release;
1894+
};
18151895
09ACF0302316DB0B004A4A61 /* Debug */ = {
18161896
isa = XCBuildConfiguration;
18171897
buildSettings = {
@@ -1855,18 +1935,22 @@
18551935
3A5C8B9922E0109200354740 /* Debug */ = {
18561936
isa = XCBuildConfiguration;
18571937
buildSettings = {
1938+
CODE_SIGN_IDENTITY = "-";
18581939
CODE_SIGN_STYLE = Automatic;
1859-
DEVELOPMENT_TEAM = K78T9LD5UA;
1940+
DEVELOPMENT_TEAM = "";
18601941
PRODUCT_NAME = "$(TARGET_NAME)";
1942+
PROVISIONING_PROFILE_SPECIFIER = "";
18611943
};
18621944
name = Debug;
18631945
};
18641946
3A5C8B9A22E0109200354740 /* Release */ = {
18651947
isa = XCBuildConfiguration;
18661948
buildSettings = {
1949+
CODE_SIGN_IDENTITY = "-";
18671950
CODE_SIGN_STYLE = Automatic;
1868-
DEVELOPMENT_TEAM = K78T9LD5UA;
1951+
DEVELOPMENT_TEAM = "";
18691952
PRODUCT_NAME = "$(TARGET_NAME)";
1953+
PROVISIONING_PROFILE_SPECIFIER = "";
18701954
};
18711955
name = Release;
18721956
};
@@ -2192,6 +2276,15 @@
21922276
defaultConfigurationIsVisible = 0;
21932277
defaultConfigurationName = Release;
21942278
};
2279+
09A05C7E24BE09EF0010C78B /* Build configuration list for PBXNativeTarget "ADT" */ = {
2280+
isa = XCConfigurationList;
2281+
buildConfigurations = (
2282+
09A05C7C24BE09EF0010C78B /* Debug */,
2283+
09A05C7D24BE09EF0010C78B /* Release */,
2284+
);
2285+
defaultConfigurationIsVisible = 0;
2286+
defaultConfigurationName = Release;
2287+
};
21952288
09ACF02F2316DB0B004A4A61 /* Build configuration list for PBXNativeTarget "divideandconquer" */ = {
21962289
isa = XCConfigurationList;
21972290
buildConfigurations = (
12.5 KB
Binary file not shown.
8.2 KB
Binary file not shown.

‎alg-cpp.xcodeproj/xcuserdata/junl.xcuserdatad/xcschemes/xcschememanagement.plist‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7+
<key>ADT.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>16</integer>
11+
</dict>
712
<key>alg-cpp.xcscheme_^#shared#^_</key>
813
<dict>
914
<key>orderHint</key>

‎alg-cpp.xcodeproj/xcuserdata/junlongj.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@
4242
ignoreCount = "0"
4343
continueAfterRunningActions = "No"
4444
filePath = "tree/main.cpp"
45-
timestampString = "599828687.318513"
45+
timestampString = "614963717.443692"
4646
startingColumnNumber = "9223372036854775807"
4747
endingColumnNumber = "9223372036854775807"
48-
startingLineNumber = "118"
49-
endingLineNumber = "118"
50-
landmarkName = "main(int argc, const char * argv[])"
51-
landmarkType = "9">
48+
startingLineNumber = "175"
49+
endingLineNumber = "175">
5250
</BreakpointContent>
5351
</BreakpointProxy>
5452
</Breakpoints>

‎alg-cpp.xcodeproj/xcuserdata/junlongj.xcuserdatad/xcschemes/xcschememanagement.plist‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<dict>
55
<key>SchemeUserState</key>
66
<dict>
7+
<key>ADT.xcscheme_^#shared#^_</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>16</integer>
11+
</dict>
712
<key>alg-cpp.xcscheme_^#shared#^_</key>
813
<dict>
914
<key>orderHint</key>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /