主观

阅读以下说明,回答问题1~4,将解答填入对应的解答栏内。

[说明] 假设二叉树采用连接存储结构进行存储,root 指向根接点,p 所指结点为任一给定的结点,编写一个求从根结点到p所指结点之间路径的函数。

 void path (root, p)

 btree * root, * p;

 {

   Btree *stack[m0], *s;

   int tag[m0], top =0, i, find =0;

   s =root;

   do

   {

     while (s ! = NULL)

     {

       stack [top] = s;

       tag[top] =0;

       ((1))

      }

      if (top >0)

      {

         ((2))

      if (tag[top] = =1)

      {

        if((3))

         {

           for (i=1; i< =top; i+ + printf ("%d" ,stack[i]- >data);

           find=1;

         }

         else top - -;

      }

      if((4))

      {

      p=p- >right;

      ((5))

      }

     }

   } while (find || (s! = NULL && top ! =0));

 }

参考答案
您可能感兴趣的试题

阅读以下说明和Java 码,将应填入(n)处的字名写在的对应栏内。

[说明] 编写一个学生类Student,要求:

 (1) 学生类Student 属性有:

 id: long 型,代表学号

 name: String类对象,代表姓名

 age: int 型,代表年龄

 sex: boolen 型,代表性别(其中:true 表示男,false 表示女)

 phone: String 类对象,代表联系电话

 (2) 学生类Student 的方法有:

 Student (long i,String n,int a,boolean s,String p)

 :有参构造函数,形参表中的参数分别初始化学号、姓名、

 年龄、性别和联系电话。

 int getAge ():获取年龄作为方法的返回值。

 boolean getSex ():获取性别作为方法的返回值。

 String getPhone ():获取联系电话作为方法的返回值。

 public String to String ():以姓名:性别:学号:联系电话的形式作为方法的返

    import java. applet. Applet;

 import java. awt.* ;

 public class Student extends Applet {

 long id;

  String name, phone;

 int age;

 boolean sex;

     Student(long i, String n, int a, boolean s, String p)

   {

   id=i;

   name = n;

   age = a;

   sex= s;

   phone = p;

   {

   public void paint( Graphics g)

   {

   Student x= new Student (5000," xiaoliu" , 89, true, " 8989898" );

    (1);

    (2) 

     g. drawstring( x. getPhone( ), 140,140);

   }

     int getAge( )

      { return age; }

     boolean getsex ( )

      { return sex; }

     String getPhone( )

      { return phone; }

     String ToString( )

     {

       (3) 

   }

 }

¥

订单号:

遇到问题请联系在线客服

订单号:

遇到问题请联系在线客服