Skip to content

Commit 98dd3e1

Browse files
committed
小改动
1 parent 2e3bbf7 commit 98dd3e1

22 files changed

Lines changed: 824 additions & 49 deletions

File tree

-13 Bytes
Binary file not shown.
-22 Bytes
Binary file not shown.
-13 Bytes
Binary file not shown.

‎Cpp/.cproject‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,28 @@
2424
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug.582268115" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug">
2525
<option id="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level.884540644" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
2626
<option id="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level.918732919" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
27+
<option id="gnu.cpp.compiler.option.include.paths.1673474582" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
28+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src&quot;"/>
29+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\algorithms&quot;"/>
30+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\pointer&quot;"/>
31+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\test&quot;"/>
32+
</option>
2733
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1468091354" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
2834
</tool>
2935
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.9562245" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug">
3036
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.mingw.exe.debug.option.optimization.level.1000392179" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.debug.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
3137
<option id="gnu.c.compiler.mingw.exe.debug.option.debugging.level.683049240" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.debug.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
38+
<option id="gnu.c.compiler.option.include.paths.1498230308" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
39+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\test&quot;"/>
40+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\pointer&quot;"/>
41+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src\algorithms&quot;"/>
42+
<listOptionValue builtIn="false" value="&quot;D:\Eclipse\Cpp\src&quot;"/>
43+
</option>
3244
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.476965598" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
3345
</tool>
3446
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.145513098" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug"/>
3547
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug.461974125" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug">
48+
<option id="gnu.cpp.link.option.libs.1071542272" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs"/>
3649
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.275757041" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
3750
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
3851
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
@@ -41,9 +54,8 @@
4154
</toolChain>
4255
</folderInfo>
4356
<sourceEntries>
44-
<entry excluding="test|pointer|com.belong.test|com.belong.pointer|com.belong|src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
45-
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="pointer"/>
46-
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="test"/>
57+
<entry excluding="Test|test|pointer|com.belong.test|com.belong|src|algorithms|com.belong.pointer" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
58+
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
4759
</sourceEntries>
4860
</configuration>
4961
</storageModule>
@@ -89,9 +101,8 @@
89101
</toolChain>
90102
</folderInfo>
91103
<sourceEntries>
92-
<entry excluding="test|pointer|com.belong.test|com.belong.pointer|com.belong|src" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
93-
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="pointer"/>
94-
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="test"/>
104+
<entry excluding="Test|test|pointer|com.belong.test|com.belong|src|algorithms|com.belong.pointer" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
105+
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
95106
</sourceEntries>
96107
</configuration>
97108
</storageModule>
@@ -118,4 +129,12 @@
118129
</storageModule>
119130
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
120131
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
132+
<storageModule moduleId="refreshScope" versionNumber="2">
133+
<configuration configurationName="Debug">
134+
<resource resourceType="PROJECT" workspacePath="/Cpp"/>
135+
</configuration>
136+
<configuration configurationName="Release">
137+
<resource resourceType="PROJECT" workspacePath="/Cpp"/>
138+
</configuration>
139+
</storageModule>
121140
</cproject>

‎Cpp/pointer/PointerTest.c‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎Cpp/src/algorithms/algorithms.cpp‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "algorithms.h"
2+
/*
3+
* BitMap.cpp
4+
* 位图算法
5+
* Created on: 2017年8月24日
6+
* Author: belong
7+
*/
8+
/*
9+
* BitMap.cpp
10+
* 位图算法
11+
* Created on: 2017年8月24日
12+
* Author: belong
13+
*/
14+
int Kadane(const int array[], size_t length, unsigned int& left, unsigned int& right)
15+
{
16+
unsigned int i, cur_left, cur_right;
17+
int cur_max, max;
18+
19+
cur_max = max = left = right = cur_left = cur_right = 0;
20+
21+
for(i = 0; i < length; ++i)
22+
{
23+
cur_max += array[i];
24+
25+
if(cur_max > 0)
26+
{
27+
cur_right = i;
28+
29+
if(max < cur_max)
30+
{
31+
max = cur_max;
32+
left = cur_left;
33+
right = cur_right;
34+
}
35+
}
36+
else
37+
{
38+
cur_max = 0;
39+
cur_left = cur_right = i + 1;
40+
}
41+
}
42+
43+
return max;
44+
}

‎Cpp/src/algorithms/algorithms.h‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <cstdio>
4+
#include <cstring>
5+
#include <fstream>
6+
#include <string>
7+
#include <vector>
8+
#include <algorithm>
9+
#include <iterator>
10+
11+
#define SHIFT 5
12+
#define MAXLINE 32
13+
#define MASK 0x1F
14+
15+
using namespace std;
16+
/*
17+
* algorithms.h
18+
*
19+
* Created on: 2017年8月24日
20+
* Author: belong
21+
*/
22+
23+
int Kadane(const int array[], size_t length, unsigned int& left, unsigned int& right);
24+
25+

‎Cpp/src/algorithms/bitmap.h‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#include "algorithms.h"
2+
/*
3+
* BitMap.cpp
4+
* 位图算法
5+
* Created on: 2017年8月24日
6+
* Author: belong
7+
*/
8+
void setbit(int *bitmap, int i){
9+
bitmap[i >> SHIFT] |= (1 << (i & MASK));
10+
}
11+
12+
bool getbit(int *bitmap1, int i){
13+
return bitmap1[i >> SHIFT] & (1 << (i & MASK));
14+
}
15+
16+
size_t getFileSize(ifstream &in, size_t &size){
17+
in.seekg(0, ios::end);
18+
size = in.tellg();
19+
in.seekg(0, ios::beg);
20+
return size;
21+
}
22+
23+
char * fillBuf(const char *filename){
24+
size_t size = 0;
25+
ifstream in(filename);
26+
if(in.fail()){
27+
cerr<< "open " << filename << " failed!" << endl;
28+
exit(1);
29+
}
30+
getFileSize(in, size);
31+
32+
char *buf = (char *)malloc(sizeof(char) * size + 1);
33+
if(buf == NULL){
34+
cerr << "malloc buf error!" << endl;
35+
exit(1);
36+
}
37+
38+
in.read(buf, size);
39+
in.close();
40+
buf[size] = '\0';
41+
return buf;
42+
}
43+
void setBitMask(const char *filename, int *bit){
44+
char *buf, *temp;
45+
temp = buf = fillBuf(filename);
46+
char *p = new char[11];
47+
int len = 0;
48+
while(*temp){
49+
if(*temp == '\n'){
50+
p[len] = '\0';
51+
len = 0;
52+
//cout<<p<<endl;
53+
setbit(bit, atoi(p));
54+
}else{
55+
p[len++] = *temp;
56+
}
57+
temp++;
58+
}
59+
delete buf;
60+
}
61+
62+
void compareBit(const char *filename, int *bit, vector<int> &result){
63+
char *buf, *temp;
64+
temp = buf = fillBuf(filename);
65+
char *p = new char[11];
66+
int len = 0;
67+
while(*temp){
68+
if(*temp == '\n'){
69+
p[len] = '\0';
70+
len = 0;
71+
if(getbit(bit, atoi(p))){
72+
result.push_back(atoi(p));
73+
}
74+
}else{
75+
p[len++] = *temp;
76+
}
77+
temp++;
78+
}
79+
delete buf;
80+
}
81+
82+
int bitMapTest(){
83+
vector<int> result;
84+
unsigned int MAX = (unsigned int)(1 << 31);
85+
unsigned int size = MAX >> 5;
86+
int *bit1;
87+
88+
bit1 = (int *)malloc(sizeof(int) * (size + 1));
89+
if(bit1 == NULL){
90+
cerr<<"Malloc bit1 error!"<<endl;
91+
exit(1);
92+
}
93+
94+
memset(bit1, 0, size + 1);
95+
setBitMask("file1", bit1);
96+
compareBit("file2", bit1, result);
97+
delete bit1;
98+
99+
cout<<result.size();
100+
sort(result.begin(), result.end());
101+
vector< int >::iterator it = unique(result.begin(), result.end());
102+
103+
ofstream of("result");
104+
ostream_iterator<int> output(of, "\n");
105+
copy(result.begin(), it, output);
106+
107+
return 0;
108+
}
109+
110+
111+

‎Cpp/src/main.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bitmap.h>
2+
#include "pointer.h"
3+
#include "algorithms.h"
4+
5+
6+
/*
7+
* main.c
8+
*
9+
* Created on: 2017年8月23日
10+
* Author: belong
11+
*/
12+
13+
int main(int args,char* argv[]){
14+
// int array={-2,1,-3,4,-1,2,1,-5,4};
15+
// pointerFunTest();
16+
// pointerTest();
17+
// funPointerTest();
18+
// bitMapTest();
19+
// Kadane(array, array.length, 0, array.length-1);
20+
return 0;
21+
}
22+
23+

‎Cpp/src/pointer/pointer.c‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "pointer.h"
2+
3+
/**
4+
* 指针测试
5+
*/
6+
int pointerTest(void){
7+
char* str = "ABCDEFGHIJK";
8+
int* pt = (int*)str;
9+
printf("%c\n%s\n",*(str+1),(char*)(pt+2));
10+
printf(str);
11+
printf("\n");
12+
printf(pt);
13+
printf("\n测试指针类型的大小\n");
14+
printf("char*:%d\n",sizeof(str));
15+
printf("int*:%d\n",sizeof(pt));
16+
return 0;
17+
}
18+
19+
/*
20+
* 求最小值
21+
* 返回值是int类型,返回两个整数中较小的一个
22+
*/
23+
int min(int a, int b) {
24+
return a < b ? a : b;
25+
}
26+
27+
/*
28+
* 求最大值
29+
* 返回值是int类型,返回两个整数中较大的一个
30+
*/
31+
int max(int a, int b) {
32+
return a > b ? a : b;
33+
}
34+
35+
/**
36+
* 函数指针测试类具体实现
37+
*/
38+
int funPointerTest()
39+
{
40+
printf("------------------------------ Start\n");
41+
int (*f)(int, int); // 声明函数指针,指向返回值类型为int,有两个参数类型都是int的函数
42+
f = max; // 函数指针f指向求最大值的函数max
43+
int c = (*f)(1, 2);
44+
printf("The max value is %d \n", c);
45+
f = min; // 函数指针f指向求最小值的函数min
46+
c = (*f)(1, 2);
47+
printf("The min value is %d \n", c);
48+
printf("------------------------------ End\n");
49+
getchar();
50+
return 0;
51+
}
52+
53+
int pointerFunTest()
54+
{
55+
printf("------------------------------ Start\n");
56+
int *p1 = NULL;
57+
printf("The memeory address of p1 = 0x%x \n", p1);
58+
p1 = f(1, 2);
59+
printf("The memeory address of p1 = 0x%x \n", p1);
60+
printf("*p1 = %d \n", *p1);
61+
printf("------------------------------ End\n");
62+
getchar();
63+
return 0;
64+
}
65+
66+
/*
67+
* 指针函数的定义
68+
* 返回值是指针类型int *
69+
*/
70+
int *f(int a, int b) {
71+
int *p = (int *)malloc(sizeof(int));
72+
printf("The memeory address of p = 0x%x \n", p);
73+
memset(p, 0, sizeof(int));
74+
*p = a + b;
75+
printf("*p = %d \n", *p);
76+
return p;
77+
}

0 commit comments

Comments
 (0)