首页 \ 问答 \ Xcode 8.2 Playground中描述的“PAGE”格式是什么?(Which is the format described 'PAGE' in Xcode 8.2 Playground?)

Xcode 8.2 Playground中描述的“PAGE”格式是什么?(Which is the format described 'PAGE' in Xcode 8.2 Playground?)

我从这里克隆了RxSwift。

当我打开Rx.playground时,我遇到了如下所示的丰富文档。

这是什么格式?
我用谷歌搜索'xcode page',但搜索结果非常模糊:[

在此处输入图像描述


I cloned RxSwift from here.

When I opened Rx.playground I faced such a rich document as shown below.

Which is the format of this?
I googled 'xcode page' but the search result is so fuzzy :[

enter image description here


原文:https://stackoverflow.com/questions/41253795
更新时间:2022-11-02 12:11

最满意答案

在这里,我将您的示例输入拆分为如何使用堆栈以及在每个输入处做出的决策的表示。

//    _ = nullptr or empty
//    # = pointer to subtree (not just a number)
// | ___ |     |     |     begin (empty element on stack)
// | 2__ |     |     |  2  make number node and set to top->left if empty, else top->right
// | 2+_ |     |     |  +  set top->input if not set, else pop parent into left of new node
// | 2+_ | ___ |     |  (  make new node on stack
// | 2+_ | 3__ |     |  3  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*_ |     |  *  set top->input if not set, else pop parent into left of new node
// | 2+_ | 3*_ | ___ |  (  make new node on stack
// | 2+_ | 3*_ | 2__ |  2  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*_ | 2+_ |  +  set top->input if not set, else pop parent into left of new node
// | 2+_ | 3*_ | 2+2 |  2  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*# |     |  )  pop it off into its parent
// | 2+# |     |     |  )  pop it off into its parent
// | #+_ |     |     |  +  set top->input if not set, else pop parent into left of new node
// | #+5 |     |     |  5  make number node and set to top->left if empty, else top->right

请注意,我有许多重复的语句,一个类型(一个用于)一个用于数字0-9 ,一个用于每个操作+-*/ 。 您已经在代码中使用了这些分区,因此您处于正确的轨道上。

(唯一的工作应该是在堆栈顶部创建一个新节点。在你的代码中,没有必要设置input = '('因为它将被实际输入覆盖以及它在堆栈就是跟踪它所需要的所有东西。你应该将input初始化为'\0'或其他意味着空的东西。

)的工作应该是从堆栈顶部弹出并将其放在需要去的地方。 如果它是null,那么它将是下一个顶部的左边节点,否则它将是顶部的右边节点。 你不需要像你一样循环堆栈,因为它总是只是我们对弹出感兴趣的顶部。

一个数字的工作应该是将自己创建为一个新节点并将自己置于需要去的地方。 就像)如果它是null那么它将是顶部的左边节点,否则它将是顶部的右边节点。 在您的代码中,您创建节点但不要将它放在堆栈之外的任何位置。 它在那里没有任何好处,因为数字节点将始终是叶节点(没有右边或左边)。

最后,操作的工作应该是简单地将自己设置为顶部的input 。 但是,有一个特殊情况,顶部已经填充(当你做1+2+31+2是顶部的节点)。 那么你在这种情况下可以做的就是从顶部弹出,在顶部推一个新节点,在左边添加旧顶部,然后将自己设置为顶部input 。 你不需要循环。

完成所有操作后,您只需设置root = tree_stack.top()

如果你想要我可以提供的代码,但我希望我的解释是足够的。

代码:这似乎对我有用

void Expression_Tree::build_expression_tree(char input[], int size)
{
  // assuming empty tree_stack, it shouldn't really be a member 
  // variable since its only used for building
  //std::stack<ETNode*> tree_stack;

  // make empty node, should really make a default constructor set all this up
  tree_stack.push(new ETNode);
  tree_stack.top()->left  = nullptr;
  tree_stack.top()->right = nullptr;
  tree_stack.top()->input = '\0';

  for (int i = 0; i < size; i++)
  {
    if (input[i] == ' ')
    {
      i++;
    }
    if (input[i] >= '0' && input[i] <= '9') // this 9 had a typo before
    {
      // create number leaf
      ETNode *temp = new ETNode;
      temp->left = nullptr;
      temp->right = nullptr; 
      temp->input = input[i];

      // put where it needs to go
      if (tree_stack.top()->left == nullptr)
        tree_stack.top()->left = temp;
      else
        tree_stack.top()->right = temp;
    }
    else if (input[i] == '(')
    {
      // make empty node
      ETNode *temp = new ETNode;
      temp->left = nullptr;
      temp->right = nullptr;
      temp->input = '\0';

      tree_stack.push(temp);
    }
    else if (input[i] == ')')
    {
      // pop top from the stack
      ETNode *temp = tree_stack.top();
      tree_stack.pop();

      // put where it needs to go
      if (tree_stack.top()->left == nullptr)
        tree_stack.top()->left = temp;
      else
        tree_stack.top()->right = temp;
    }
    else if (input[i] == '+' || input[i] == '-' || input[i] == '*' || input[i] == '/')
    {
      // shuffle node if already filled
      if (tree_stack.top()->input != '\0')
      {
        ETNode *old = tree_stack.top();
        tree_stack.pop();

        ETNode *temp = new ETNode;
        temp->left = old;
        temp->right = nullptr;

        tree_stack.push(temp);
      }

      tree_stack.top()->input = input[i];
    }
  }

  // set root node
  root = tree_stack.top();
}

Here I've split up your example input into a representation of how the stack can be used and the decisions made at each input.

//    _ = nullptr or empty
//    # = pointer to subtree (not just a number)
// | ___ |     |     |     begin (empty element on stack)
// | 2__ |     |     |  2  make number node and set to top->left if empty, else top->right
// | 2+_ |     |     |  +  set top->input if not set, else pop parent into left of new node
// | 2+_ | ___ |     |  (  make new node on stack
// | 2+_ | 3__ |     |  3  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*_ |     |  *  set top->input if not set, else pop parent into left of new node
// | 2+_ | 3*_ | ___ |  (  make new node on stack
// | 2+_ | 3*_ | 2__ |  2  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*_ | 2+_ |  +  set top->input if not set, else pop parent into left of new node
// | 2+_ | 3*_ | 2+2 |  2  make number node and set to top->left if empty, else top->right
// | 2+_ | 3*# |     |  )  pop it off into its parent
// | 2+# |     |     |  )  pop it off into its parent
// | #+_ |     |     |  +  set top->input if not set, else pop parent into left of new node
// | #+5 |     |     |  5  make number node and set to top->left if empty, else top->right

Note that I have many duplicate statements, one type for ( one for ) one for a number 0-9 and one for each operation +-*/. You already have these divisions in your code so you're on the right track.

('s only job should be to create a new node on the top of the stack. In your code, there is no point to set input = '(' because its going to be overwritten by an actual input later and its position in the stack is all that's needed to keep track of it. You should initialize input to '\0' or something else meaning empty.

)'s job should be to pop the top off the stack and put it where it needs to go. That'll be either the next top's left node if its null, otherwise it'll be top's right node. You don't need to loop down the stack like you do, because it'll always just be the top that we're interested in popping.

A number's job should be to create itself as a new node and put itself where it needs to go. Just like ) that'll either be the top's left node if its null, otherwise it'll be top's right node. In your code, you make the node but you don't put it anywhere besides on the stack. Its not doing any good there because a number node will always be a leaf node (no right or left).

Finally an operation's job should be to simply set itself to the top's input. However, there's a special case where the top has already been filled in (when you do 1+2+3 the 1+2 is the node on top). So what you can do in that case is pop off the top, push a new node on top, add the old top as the left, and THEN just set itself to top's input. You don't need a loop.

After all is done, you can just set root = tree_stack.top().

If you want the code I can supply it but I hope my explanation is enough.

Code: This seems to work for me

void Expression_Tree::build_expression_tree(char input[], int size)
{
  // assuming empty tree_stack, it shouldn't really be a member 
  // variable since its only used for building
  //std::stack<ETNode*> tree_stack;

  // make empty node, should really make a default constructor set all this up
  tree_stack.push(new ETNode);
  tree_stack.top()->left  = nullptr;
  tree_stack.top()->right = nullptr;
  tree_stack.top()->input = '\0';

  for (int i = 0; i < size; i++)
  {
    if (input[i] == ' ')
    {
      i++;
    }
    if (input[i] >= '0' && input[i] <= '9') // this 9 had a typo before
    {
      // create number leaf
      ETNode *temp = new ETNode;
      temp->left = nullptr;
      temp->right = nullptr; 
      temp->input = input[i];

      // put where it needs to go
      if (tree_stack.top()->left == nullptr)
        tree_stack.top()->left = temp;
      else
        tree_stack.top()->right = temp;
    }
    else if (input[i] == '(')
    {
      // make empty node
      ETNode *temp = new ETNode;
      temp->left = nullptr;
      temp->right = nullptr;
      temp->input = '\0';

      tree_stack.push(temp);
    }
    else if (input[i] == ')')
    {
      // pop top from the stack
      ETNode *temp = tree_stack.top();
      tree_stack.pop();

      // put where it needs to go
      if (tree_stack.top()->left == nullptr)
        tree_stack.top()->left = temp;
      else
        tree_stack.top()->right = temp;
    }
    else if (input[i] == '+' || input[i] == '-' || input[i] == '*' || input[i] == '/')
    {
      // shuffle node if already filled
      if (tree_stack.top()->input != '\0')
      {
        ETNode *old = tree_stack.top();
        tree_stack.pop();

        ETNode *temp = new ETNode;
        temp->left = old;
        temp->right = nullptr;

        tree_stack.push(temp);
      }

      tree_stack.top()->input = input[i];
    }
  }

  // set root node
  root = tree_stack.top();
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)