feat: 统一 cpp 文件编码格式为 utf-8

This commit is contained in:
tracyxiong1
2023-01-02 20:39:00 +08:00
parent ade7173887
commit 368eda305f
63 changed files with 327 additions and 327 deletions

View File

@@ -1,5 +1,5 @@
/*
设计一个堆栈的类模板Stack在模板中用类型参数T表示栈中存放的数据用非类型参数MAXSIZE代表栈的大小。
设计一个堆栈的类模板Stack在模板中用类型参数T表示栈中存放的数据用非类型参数MAXSIZE代表栈的大小。
*/
#include<iostream>
using namespace std;
@@ -32,14 +32,14 @@ class Stack{
}
};
/*
原型:
template <模板参数列表>
返回值类型 类模板名<模板参数名表>::成员函数名 (参数列表){};
原型:
template <模板参数列表>
返回值类型 类模板名<模板参数名表>::成员函数名 (参数列表){};
*/
template<class T, int MAXSIZE>
void Stack<T,MAXSIZE>::push(T e){
if(full()){
cout<<"栈已满,不能再添加元素了!";
cout<<"栈已满,不能再添加元素了!";
return;
}
elem[++top]=e;
@@ -48,7 +48,7 @@ void Stack<T,MAXSIZE>::push(T e){
template<class T, int MAXSIZE>
T Stack<T,MAXSIZE>::pop(){
if(empty()){
cout<<"栈已空,不能再弹出元素了!"<<endl;
cout<<"栈已空,不能再弹出元素了!"<<endl;
return 0;
}
return elem[top--];
@@ -57,7 +57,7 @@ T Stack<T,MAXSIZE>::pop(){
int main(int argc, char const *argv[])
{
//类模板实例化
//类模板实例化
Stack<int,10> iStack;
Stack<char,10> cStack;
iStack.setEmpty();

View File

@@ -1,4 +1,4 @@
//设计一通用数组类,它能够直接存取数组元素,并能够对数组进行从大到小的排序。
//设计一通用数组类,它能够直接存取数组元素,并能够对数组进行从大到小的排序。
#include<iostream>
#include<cstring>
@@ -20,7 +20,7 @@ class Array{
template<class T> T& Array<T>::operator[](int i){
if(i<0||i>Size-1){
cout<<"\n数组下标越界!"<<endl;
cout<<"\n数组下标越界!"<<endl;
exit(1);
}
return a[i];
@@ -39,7 +39,7 @@ template<class T> void Array<T>::Sort(){
a[i]=t;
}
}
//template <> 返回类型 类模板名<特化的数据类型>::特化成员函数名(参数表){}
//template <> 返回类型 类模板名<特化的数据类型>::特化成员函数名(参数表){}
template<> void Array<char *>::Sort(){
int p;
for(int i=0;i<Size-1;i++){