Question: Data structures and algorithms Q 1 ) assume the number of characters in the string is n , not including the null terminator character. for

Data structures and algorithms Q1) assume the number of characters in the string is n, not including the null terminator character.
for the following code write how many times each operation will be done (at worst)using n.
1-<
2-[]
3-=
4-++
5-==
char* replace(char* str, char oldChar, char newChar){
int size = length(str)+1;
char* newVer = malloc(size*sizeof(char));
for(int i=0; i < size; i++){
if(str[i]==oldChar){
newVer[i]=newChar;
}else{ newVer[i]=str[i];
}}
return newVer; }
Q2) assume the number of characters in the string is n, not including the null terminator character.
for the following code write how many times each operation will be done (at worst)using n.
1-<
2-[]
3-=
4->=
5-++
char* toUpper(char* str){
int size = length(str)+1;
char* newVer = malloc(size*sizeof(char)); for(int i=0; i < size; i++){
if(str[i]>='a' && str[i]<='z'){ newVer[i]= str[i]-32;
}else{
newVer[i]= str[i]; }}
return newVer; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!