كل الأمثلة

أمثلة

بناء شجرة بحث ثنائية بلغة C++‎

سبعة مفاتيح تُدرَج واحدًا تلو الآخر: كل مقارنة ترسل المفتاح يسارًا أو يمينًا في الشجرة، بجانب دالة الإدراج العودية في C++‎ ومكدس استدعاءاتها.

صُنع هذا الفيديو بمهارة الخوارزميات المرئية.

  • 1:00
  • الخوارزميات المرئية
  • بصوت Sulafat
  • الإنجليزية

صُنع من فكرة

Insert 50, 30, 70, 20, 40, 60, 80 into a binary search tree, in C++

التفريغ النصي للفيديو

How do you add keys while keeping a binary search tree ordered?

The code inserts these 7 keys. Smaller keys go left; others go right. Orange marks execution; green marks completed nodes.

Line 7 finds nullptr, so line 8 creates the root, 50.

30 is smaller than 50, so recursion goes left and creates 30.

70 is greater than 50, so it becomes the right child.

20 goes left of 30; 40 goes right of 30. Then 60 passes right of 50 and goes left of 70.

80 reaches 50. Which way will you go?

80 exceeds 50 and 70, so 80 becomes 70's right child.

The smaller-left, others-right rule holds. Comparisons guide insertion, but a skewed tree makes each insertion linear.

موضوعك، مرسومًا في دقيقة تقريبًا.

أول 2 من فيديوهاتك مجانًا، مدة كلٍّ منها حتى دقيقة واحدة، مع علامة مائية. لا حاجة إلى بطاقة دفع. المنتج كاملًا، بكل الأصوات والأساليب.