Professional Documents
Culture Documents
עבודת חנוכה
עבודת חנוכה
ב .הסיבוכיות של פונקציה זו היא , )o(nש n-מסמל את מספר האלמנטים בתור ,ואנו מריצים לולאה על אורך
התור פעם אחת.
:1 סעיף, 3 שאלה
;int count_of_0 = 0
))(while (!q.IsEmpty
{
)if (q.Head() == 0
{
;)(q.Remove
;++of_0count_
}
)else if (q.Head() < 0
{
;))(s1.Push(q.Remove
}
)else if (q.Head() > 0
{
;))(s2.Push(q.Remove
}
}
))(while (!s2.IsEmpty
;))(s3.Push(s2.Pop
)++for (int i = 0; i < count; i
;)s3.Push(0
))(while (!s1.IsEmpty
;))(s3.Push(s1.Pop
))(while (!s3.IsEmpty
;))(q.Insert(s3.Pop
;return q
}
שאלה :3סעיף :2
שאלה 3סעיף :3
הסיבוכיות של קוד זה היא )o(nבגלל שאנו רצים על התור המתקבל בפרמטר פעמיים ,כש nמייצג את אלמנט
אחד בתור.