두 프로그램을 시간복잡도로 비교부탁드립니다.
나려
첫번째꺼고.
#include string.h
#define MAX_SIZE 100
char string1[MAX_SIZE], *s=string1;
char string2[MAX_SIZE], *t=string2;
void strnins(char *s, char *t, int i)
{
char string[MAX_SIZE], *temp = string;
if(i 0 && i strlen(s)) {
fprintf(strerr, Position is out of bounds \n);
exit(EXIT_FAILURE);
}
if (!strlen(s))
strcpy(s,t);
else if (strlen(t)) {
strncpy(temp, s, i);
strcat(temp, t);
strcat(temp, (s+i));
strcpy(s, temp);
}
두번째꺼.
#include stdio.h
#include string.h
#define MAX_SIZE 100
void strnins(char *s, char *t, int i)
{
char string[MAX_SIZE]=;
if (!strlen(s))
strcpy(s,t);
else if (strlen(t))
{
strncpy(string, s, i);
strcat(string, t);
strcat(string, (s+i));
strcpy(s, string);
}
}
int main()
{
char str1[MAX_SIZE]=abcd;
char str2[MAX_SIZE]=efg;
strnins(str1, str2, 2);
printf(%s\n, str1);
return 0;
}
대충보면 어림잡아 알꺼같긴한데 왠지 꺼림직한 기분..
누군가 물어보면 설명해주긴 어려워서 제대로 자세히 알고싶어요,
구체적으로 자세히 설명좀 부탁드리면 진짜 감사하겠습니다.