![在这里插入图片描述](https://img-blog.csdnimg.cn/a0839a53c7bb40e9a8d06f010d5287d7.png)
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
vector<int>op;
vector<int>::const_iterator it;
int m=10,temp;
while(m--)
{
cin>>temp;
op.push_back(temp);
}
sort(op.begin(),op.end());
for(it=op.begin();it!=op.end();it++)
cout<<*it<<' ';
cout<<endl;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/51557fe3452a43dd8cc9e630213232e4.png)
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
struct student
{
int num;
string name;
string gender;
int age;
};
bool cmp(student a,student b)
{
return a.num<b.num;
}
int sum(string temp)
{
int s=0;
for(int i=0;i<temp.length();i++)
s+=(temp[i]-'0')*pow(10,temp.length()-1-i);
return s;
}
int main()
{
student stu[1000];
stu[0]={10,"wes","f",23};
stu[1]={20,"ert","f",45};
stu[2]={30,"str","t",89};
char op;
int i=2,m=0;
string arr[4];
cout<<"请输入操作"<<endl;
while(cin>>op)
{
if(op=='I')
{
string data;
cin>>data;
int st=0,end=-1,m=0;
for(int j=0;j<data.length();j++)
{
if(data[j]==',')
{
end=j;
string temp=data.substr(st,end-st);
arr[m++]=temp;
st=j+1;
}
}
arr[m++]=data.substr(st,data.length()-st);
stu[++i].num=sum(arr[0]);
stu[i].name=arr[1];
stu[i].gender=arr[2];
stu[i].age=sum(arr[3]);
}
else if(op=='D')
{
int num;
cin>>num;
for(int j=0;j<=i;j++)
if(stu[j].num==num)
{
for(int k=j;k<i;k++)
{
stu[k].num=stu[k+1].num;
stu[k].name=stu[k+1].name;
stu[k].gender=stu[k+1].gender;
stu[k].age=stu[k+1].age;
}
i--;
break;
}
}
else
break;
sort(stu,stu+i+1,cmp);
for(int j=0;j<=i;j++)
cout<<"("<<stu[j].num<<","<<stu[j].name<<","<<stu[j].gender<<","<<stu[j].age<<") ";
cout<<endl;
}
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/83aa485ba2a3466e84d9fda19703c60c.png)
#include<iostream>
#include<string>
using namespace std;
struct TreeNode
{
char data;
TreeNode* leftNode;
TreeNode* rightNode;
};
TreeNode* Build(string str1,string str2)
{
if(str1.length()==0)
return NULL;
char c=str1[str1.length()-1];
TreeNode* root=(TreeNode*)malloc(sizeof(TreeNode));
root->data=c;
int pos=str2.find(c);
root->leftNode=Build(str1.substr(0,pos),str2.substr(0,pos));
root->rightNode=Build(str1.substr(pos,str1.length()-pos-1),str2.substr(pos+1));
return root;
}
void posOrder(TreeNode* root)
{
if(root==NULL)
return;
cout<<root->data;
posOrder(root->leftNode);
posOrder(root->rightNode);
return;
}
int main()
{
string str1,str2;
cout<<"请输入两个字符串:"<<endl;
while(cin>>str1>>str2)
{
if(str1=="00"&&str2=="00")
break;
cout<<"前序遍历结果为:";
TreeNode* root=Build(str1,str2);
posOrder(root);
cout<<endl;
cout<<"请输入两个字符串,00 00作为程序结束标志"<<endl;
}
return 0;
}