用c++编写一个含sequence类的程序
时间: 2023-05-13 11:04:33 浏览: 139
一个C++语言编写的程序
非常感谢您的提问!以下是一个简单的含sequence类的C程序示例:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int *data;
int length;
} Sequence;
void init(Sequence *seq, int length) {
seq->data = (int *)malloc(length * sizeof(int));
seq->length = length;
}
void set(Sequence *seq, int index, int value) {
seq->data[index] = value;
}
int get(Sequence *seq, int index) {
return seq->data[index];
}
void print(Sequence *seq) {
for (int i = 0; i < seq->length; i++) {
printf("%d ", seq->data[i]);
}
printf("\n");
}
int main() {
Sequence seq;
init(&seq, 5);
set(&seq, 0, 1);
set(&seq, 1, 2);
set(&seq, 2, 3);
set(&seq, 3, 4);
set(&seq, 4, 5);
print(&seq);
return 0;
}
希望这个程序能够帮助您!
阅读全文