빅오를 구하고 싶어요~
애기
PrintLot( List L ,List X)
이 함수의 빅오를 구하는 문제입니다.
함수가 리스트List L 과 List X가 있으면
List X의 삽입데이타 값에 요소가 1,3,4,6이라면
List L의 첫번쨰 , 세번쨰, 네번쨰, 여섯번째 위치의 요소를 출력해주는 함수입니다.
이 함수의 빅오를 구하는 문제인데
while 안에 for 문이 있으니 여기 빅오가 O(n제곱) 이렇게 되는건가요??
#include stdio.h
#include stdlib.h
struct Node
{
int Element;
struct Node *Next;
};
typedef struct Node *PtrToNode;
typedef PtrToNode List;
typedef PtrToNode Position;
int IsEmpty( List L );
int IsLast( Position P, List L );
Position Find ( int X, List L );
void Delete( int X, List L );
Position FindPrevious( int X, List L );
void Insert( int X, List L, Position P );
void DeleteList( List L );
void PrintList( List L );
void PrintLots( List L, List X );
int main(void)
{
List Header, Header2, L, X;
Header = ( List )malloc ( sizeof ( struct Node) );
Header2 = ( List )malloc ( sizeof ( struct Node) );
Header-Next = NULL;
Header2-Next = NULL;
L = Header;
X = Header2;
Insert( 7, L, L );
Insert( 10, L, Find( 7, L ) );
Insert( 28, L , Find( 10, L ) );
Insert( 5, L , Find( 10, L ) );
Insert( 4, L , Find( 10, L ) );
Insert( 3, L , Find( 10, L ) );
Insert( 9, L , Find( 10, L ) );
Insert( 20, L , Find( 10, L ) );
printf(리스트 L의 요소 : );
PrintList( L );
Insert( 1, X, X );
Insert( 3, X, Find( 1, X ) );
Insert( 4, X, Find( 3, X ) );
Insert( 6, X, Find( 4, X ) );printf(리스트 X의 요소 : );
PrintList( X );
printf(리스트 X의 요소에 위치하는 리스트 L의 요소 : );
PrintLots( L , X );
return 0;
}
int IsEmpty( List L )
{
return L-Next == NULL;
}
int IsLast( Position P, List L )
{
return P-Next == NULL;
}
Position Find(int X, List L )
{
Position P;
P = L-Next;
while( P != NULL && P-Element !=X )
P = P-Next;
return P;
}
void Delete( int X, List L)
{
Position P, TmpCell;
P = FindPrevious( X, L );
if( !IsLast( P, L) )
{
TmpCell = P-Next;
P-Next = TmpCell-Next;
free( TmpCell );
}
}
Position FindPrevious( int X, List L )
{
Position P;
P = L;
while( P-Next != NULL && P-Next-Element !=X )
P = P-Next;
return P;
}
void Insert( int X, List L, Position P )
{
Position TmpCell;
TmpCell = malloc( sizeof( struct Node ) );
if( TmpCell == NULL )
printf( Out of space !!!);
TmpCell-Element = X;
TmpCell-Next = P-Next;
P-Next = TmpCell;
}
void DeleteList( List L )
{
Position P, Temp;
P = L-Next;
L-Next = NULL;
while( P != NULL )
{
Temp = P-Next;
free( P );
P = Temp;
}
}
void PrintList( List L )
{
Position P;
P = L;
while ( P-Next )
{
printf( |%d|, P-Next-Element);
P = P-Next;
}
printf(\n);
}
void PrintLots( List L, List X )
{
Position L2, X2;
int Data=0, i;
X2 = X;
while( X2-Next )
{
Data = X2-Next-Element;
L2 = L;
//printf(Data의 값 : %d = , X2-Next-Element);
//printf(실제요소의 처음값 : %d\n, L2-Next-Element);
for(i=1; iData; i++)
{
L2 = L2-Next;
}
printf( |%d|, L2-Next-Element);
X2 = X2-Next;
}
printf(\n);
}