首页 \ 问答 \ 将工程可扩展性融入应用程序(Engineering scalability into an application)

将工程可扩展性融入应用程序(Engineering scalability into an application)

这意味着什么 - 在应用程序中设计可伸缩性。 设计模式是否会使应用程序更具可扩展性? 这个问题主要是在Web应用程序或基于SOA中间件的应用程序的上下文中。


What does it mean to say - Engineering scalability into applications. Are there design patterns that would make an application more scalable? This question is mainly in the context of web applications or SOA middleware based applications.


原文:https://stackoverflow.com/questions/1074114
更新时间:2022-09-20 14:09

最满意答案

前面的大事:这是一个二叉树,而不是链表。 将其称为链接列表只会导致混淆。

在主题上,递归不是链接列表的方法。 对于一棵树它可能是。 但你有什么不起作用有几个原因。

1)没有终止条件。 递归将犁入NULL指针并做坏事。 如果nodePtr为NULL,则首先在recursiveCreate中退出。

2)您正在设置当前节点以指向错误的东西。 例如,

n->right = ptr->right;

让节点指向错误列表中的节点。 这几乎是一个糟糕的结局。 您想指向由recursiveCreate创建的节点。

让我们来看看这将是什么样子:

nodePtr LinkedList::recursiveCreate(nodePtr ptr)
{
    if (ptr == nullptr) 
    {
        return nullptr; // source tree stops here
    }
    nodePtr n = new node; //create new node
    n->elt = ptr->elt;      //copy value into that new node
    n->right = recursiveCreate(ptr->right);  //call on right node
    n->below = recursiveCreate(ptr->below);  //call on below node
    return n;
}

LinkedList::LinkedList(const LinkedList &list)
{
    nodePtr current = nullptr;

    if (list.head == nullptr) // NAG!!! For Crom's sake! 0 is not a pointer!
        head == nullptr;      // Use nullptr and get type checking working for you.

    else
    {
        head = recursiveCreate(list.head);       
    }
}

特殊奖金运营商

LinkedList & operator=(LinkedList list) // pass by reference. Copy constructor copies 
                                        // for you
{
    std::swap(head, list.head); // steal head from copy and give copy the empty   
    return *this; // all done.
}

The up front big thing: This is a binary tree, not a linked list. Calling it a linked list just leads to confusion.

On topic, recursion is not the way to go for a linked list. For a tree it could be. But what you have does not work for a couple reasons.

1) There is no terminating condition. The recursion will plow into a NULL pointer and do bad things. First off in recursiveCreate you want to exit if nodePtr is NULL.

2) You're setting the current node to point at the wrong stuff. For example,

n->right = ptr->right;

has the node pointing at a node in the wrong list. That's an almost certain bad end. You want to point at the node created by recursiveCreate.

Let's take a look at what this would have to look like:

nodePtr LinkedList::recursiveCreate(nodePtr ptr)
{
    if (ptr == nullptr) 
    {
        return nullptr; // source tree stops here
    }
    nodePtr n = new node; //create new node
    n->elt = ptr->elt;      //copy value into that new node
    n->right = recursiveCreate(ptr->right);  //call on right node
    n->below = recursiveCreate(ptr->below);  //call on below node
    return n;
}

and

LinkedList::LinkedList(const LinkedList &list)
{
    nodePtr current = nullptr;

    if (list.head == nullptr) // NAG!!! For Crom's sake! 0 is not a pointer!
        head == nullptr;      // Use nullptr and get type checking working for you.

    else
    {
        head = recursiveCreate(list.head);       
    }
}

Special bonus operator

LinkedList & operator=(LinkedList list) // pass by reference. Copy constructor copies 
                                        // for you
{
    std::swap(head, list.head); // steal head from copy and give copy the empty   
    return *this; // all done.
}

相关问答

更多
  • 而不是设置curr = phead->next ,尝试phead->next = curr 您的代码似乎是将curr的值设置为phead-> next的值,这在此代码中永远不会更改。 在curr旁边设置phead->将使得phead列表包含在curr值中创建的节点,将curr添加到链接列表中。 我希望这有帮助! Instead of setting curr = phead->next, try phead->next = curr Your code appears to be setting the v ...
  • 看起来你在递归中有点束缚。 我修改了您的方法以接受Node以及上一次迭代中的产品。 在迭代的每一步,我都更新已存在的List的值,因此不需要使用new运算符。 public static void product(Node curr, int value) { if (curr == null) { return; } else { int data = value * curr.getData(); // compute current produ ...
  • 递归是一种自我调用的方法吗? 是的,通常。 有关细节,示例和例外,请参阅Wikipedia 。 如果简化方法,您可以在自己的代码中理解递归。 您编写的代码更类似于过程代码,而Ruby通常使用更类似于此的面向对象的代码: class LinkedListNode attr_accessor :value, :next_node def initialize(value, next_node = nil) @value = value @next_node = next_node ...
  • 代码不完整。 您必须首先确保正确构造CCircularList和srcList。 此外,由于您复制了引用节点数据和下一个地址,因此节点构造函数似乎有些错误。 我认为更正确可能有些像 Node::Node(const Node& oldNode) : nData(oldNode.nData) , next(nullptr) {;} Indeeed,错误表明你传递的某些sPtr为null。 你可以查看断言做 CCircularList::CCircularList(CCircularList& srcList ...
  • 而不是newNode-> value =(* thisNode-> value); 你需要newNode-> value = thisNode-> value; Instead of newNode->value = (*thisNode->value); you need to newNode->value = thisNode->value;
  • 我想你只需要存储上一个节点(prv)。 假设您的节点有prv作为数据成员。 List(const List ©ing) : head(NULL) { Node* cur = copying.head; int size = copying.size(); Node* end = NULL; Node* prv = NULL: for(int q = 0; q < size; q++) { Node* n = new Node; ...
  • 在没有实际看到代码的情况下,我无法肯定地说,但我会说,对于链表实现, 很可能需要复制构造函数和赋值运算符,以防止您的类具有破坏的复制语义由构造函数执行的动态分配,以及析构函数执行的取消分配。 如果你看到一个过去没有这些的实现,它很可能是它被打破/错误/错误,这在互联网上并不常见,那里存在无穷无尽的初学者实现并被传递掉作为“如何做到这一点”在非同行评审的教程中。 遗憾的是,它在大学教材中甚至相当普遍。 从一本好书中学习C ++,并阅读有关三级规则的内容 。 然后删除你的实现并使用std::list ! Wit ...
  • 前面的大事:这是一个二叉树,而不是链表。 将其称为链接列表只会导致混淆。 在主题上,递归不是链接列表的方法。 对于一棵树它可能是。 但你有什么不起作用有几个原因。 1)没有终止条件。 递归将犁入NULL指针并做坏事。 如果nodePtr为NULL,则首先在recursiveCreate中退出。 2)您正在设置当前节点以指向错误的东西。 例如, n->right = ptr->right; 让节点指向错误列表中的节点。 这几乎是一个糟糕的结局。 您想指向由recursiveCreate创建的节点。 让我们来 ...
  • 要连接两个链接列表,必须使第一个列表的最后一个节点指向第二个列表的第一个节点。 Node first_list = ... // head node Node second_list = ... // head node ... Node last_node = first_list.getLastNode() last_node.setNext(second_list) 现在专注于实现getLastNode() 。 它可以通过使用递归或迭代非常简单地完成,字面上是2行。 To concatenate ...
  • 您的循环条件不正确。 您希望在有下一个节点时循环。 你正在做相反的事情: while(!copyPtr) 应该: while (copyPtr) 另请注意,如果要复制的列表为空,则复制构造函数将不正确。 在进行任何检查之前,请取消引用listObj.head 。 Your loop condition is incorrect. You want to loop while there is a next node. You are doing the opposite: while(!copyPtr ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。