数据结构求助

来源:百度知道 编辑:UC知道 时间:2024/06/25 00:33:51
题目1:输入一颗二叉树,输出先序遍历结果
2:输入串S和串T,将S中子串为T的删除,输出新串

麻烦各位了···期末作业··实在不会做·只有把所有分奉送了···

2.应该使用链表做 但是我手头只有数组的了
#include <iostream>
#include <cstring>
using namespace std;

int squeeze(char s[],const char t[]){
int index=0,j=0;
char check=s[index];
int count=0;
int len2=strlen(t);
bool move;
while(s[index]!='\0'){
move=false;
check=s[index];
for(int i=0;i<len2;i++){
if(check==t[i]){
j=index;
while(s[j]!='\0'){
s[j]=s[j+1];
j++;
} //删除T中已有的字符
count++;
move=true;
break;
}
}
if(!move)
index++;
}
return count;
}

int main(){
char s1[]={"abcdefghhh"};
const char s2[]={"cdsgh"};
int count=squeeze(s,t);
cout << "delete " << count << " characters." <<endl;
cout << s <<endl; //输出新串

return 0;
}