forked from redmouth/java2cpp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArray.h
More file actions
42 lines (34 loc) · 623 Bytes
/
Array.h
File metadata and controls
42 lines (34 loc) · 623 Bytes
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
//
// Created by levin on 17-5-12.
//
#pragma once
#include <cstddef>
template<typename T>
struct Array {
int length;
T* data;
Array () {
length = 0;
data = NULL;
}
Array (int s) {
length = s;
data = new T[length];
}
void create(int size) {
if (data)
delete[] data;
length = size;
if (length > 0)
data = new T[length];
}
void set(int elem, T val) {
data[elem] = val;
}
T& get(int pos) {
return data[pos];
}
T& operator[](int pos) {
return data[pos];
}
};