在C中实现链接列表优先级队列(implement a Linked List Priority Queue in C)
你将如何使用C中的链表来实现优先级队列?
典型的链表由
head
指向指向另一个元素的元素组成,最终由NULL
或链表尾部结束。 例:(Linked List | Head) ----> (Element | Next) ----> (Element | Next) ----> Null
在基本情况下,通过使用先进先出(添加到列表末尾,从列表的前面移除)FIFO方法将新元素添加到列表中。
但在我的情况下,必须考虑优先值。 更具体地说,每个元素可以分配1,2或3的优先级。具有最高优先级的元素被添加到列表的前面,而具有较低优先级的元素被添加到后面。 插入列表保持每个优先级的FIFO顺序。
所以,如果要一次排列以下元素:
a 3, b 1, c 2, d 3, e 2
输出应该是:
a 3, d 3, c 2, e 2, b 1
(按照优先顺序排列,以及添加的顺序,而不是标准先进先出方法,不考虑优先级)。这是我所拥有的,但它不具备优先权。 你将如何去实施优先队列?
一种方法是使用排序/优先级算法。 除了算法之外,对于我来说,一些主要的未知/困惑是如何以及在哪里存储优先级,它是否在实际元素内,例如:
(Linked List | Head)---->(a | 1 | Next)---->(b | 2 | Next)---->空
要么
q_enqueue(&q, "a", "1"); q_enqueue(&q, "b", "2");
以及如何比较优先级,同时使用指针创建排序算法。
How would you go about implementing a priority queue using a linked list in C?
The typical linked list consists of
head
pointing to an element which points to another element(s), which eventually ends byNULL
or the linked list's tail. Example:(Linked List | Head) ----> (Element | Next) ----> (Element | Next) ----> Null
In the basic scenario, new elements are added to the list by using the First-In First-Out (add to the end of the list, remove from the front of the list) FIFO approach.
In my case however, a priority value must be taken into consideration. More specifically, each element can be assigned priority of 1, 2 or 3. Elements with the highest priority are added towards the front of the list while those with lower priority are added towards the back. Insertions into the list maintain the FIFO order of each priority.
So, if one is to enqueue the following elements one at a time:
a 3, b 1, c 2, d 3, e 2
The output should be:
a 3, d 3, c 2, e 2, b 1
(ordered by priority as well as the order of being added instead of the standard First-In First-Out approach which disregards the priority).Here is what I have, but it DOES NOT feature priority. How would you go about implementing a priority queue?
One way would be to use a sorting/priority algorithm. Besides the algorithm, some of the major unknowns/confusion for me is how and where the priority would be stored, would it be within the actual element such as:
(Linked List | Head) ----> (a | 1 | Next) ----> (b | 2 | Next) ----> Null
or
q_enqueue(&q, "a", "1"); q_enqueue(&q, "b", "2");
and how would I go about comparing the priorities while working with the pointers to create the sorting algorithm.
原文:https://stackoverflow.com/questions/7383747
最满意答案
php sdk使用以下foreach语法:
foreach($sObjects as &$sObject){ ... $sObject = xx; }
这不是更新原始数组对象,因此没有任何内容发送到salesforce。 我创建了一个新数组并将新对象分配给新数组,并且它可以工作。
我希望这有助于其他人。
The php sdk was using the following foreach syntax:
foreach($sObjects as &$sObject){ ... $sObject = xx; }
This was not updating the original array object, so nothing was being sent to salesforce. I created a new array and assigned the new objects to the new array, and it works.
I hope this helps someone else.
相关问答
更多-
https://rubygems.org/gems/databasedotcom 此Gem提供对Salesforce对象的类似ActiveRecord的访问。 我好运。 它抽象了SOAP / REST协议。 After couple of try outs, I settled for Savon Gem.
-
看起来像你需要:var getSessionIdStartIndex = response.indexOf(“
”)+“ ”。length; 会话Id从 的末尾开始。 Looks like you need: var getSessionIdStartIndex = response.indexOf(" ") + “ ”.length; The session Id starts at the end of ... -
Salesforce API:创建多个人员帐户与一个案例的关系(Salesforce API: Create relationship of multiple Person Accounts to one Case)[2023-08-05]
有几种方法可以解决这个问题。 如果只有一个共同借用者,您可以在Case对象上创建一个查找字段以链接到Account / Contact Object。 如果您将有多个共同借款人,并且您只想查看与联系人相关的列表以及可能与“共同借款人”之类的关系/角色,您可以使用案例联系人角色 如果您有多个共同借款人并希望从他们的每个帐户/联系人中查看一些字段值,请创建一个类似“CaseAccount”的连接对象,以初始化案例和帐户/联系人之间的多对多关系。 There are several options to deal ... -
php sdk使用以下foreach语法: foreach($sObjects as &$sObject){ ... $sObject = xx; } 这不是更新原始数组对象,因此没有任何内容发送到salesforce。 我创建了一个新数组并将新对象分配给新数组,并且它可以工作。 我希望这有助于其他人。 The php sdk was using the following foreach syntax: foreach($sObjects as &$sObject){ ... ...
-
Salesforce - 通过API创建案例后触发自动响应规则(Salesforce - trigger auto-response rule after creating case through API)[2021-12-22]
嗯,复杂性降低几乎总是以较少的功能为代价。 API标头丢失就是其中之一。 至少在Java中,你可以使用许多可用的工具包正确地使用WSDL,在.NET中,WCF几乎是无用的,因为MS认为SOAP头不是很酷(标准被诅咒)。 因此,要么使用WSDL / SOAP,要么创建一个工作流规则,该规则将触发案例创建并将电子邮件发送到所需地址。 Well, less complexity almost always comes at the cost of less features. Loss of API header ... -
可以在Salesforce SOAP响应中添加标题和修改主体吗?(Can A Header Be Added & Body Modified In A Salesforce SOAP Response?)[2022-12-10]
我不相信你可以直接在Apex定义的WebService方法中添加任何类型的SOAP头。 如果你绝对没有其他选择,你可以通过REST Web服务(通过@RestResource注释)构建自己的自定义SOAP响应,但这是一个非常难看的解决方案。 I don't believe you can directly add any kind SOAP headers in an Apex defined WebService methods. If you have absolutely no other optio ... -
不是真正的答案,但...... 很快就会有一个关于Salesforce的REST API的网络研讨会。 使用纯HTTP和JSON,您可以避免SOAP问题:) 这是一个“开发者预览版”,这意味着可能这个功能将在今年秋冬正式发布。 https://www.developerforce.com/events/rest_developer_preview/registration.php?d=70130000000FV4P Not really an answer, but... There will be a w ...
-
salesforce rest api(salesforce rest api)[2022-01-10]
对于REST API,您不需要使用WSDL。 您可以通过访问来探索API https://开头{}实例.salesforce.com /服务/数据/ v24.0 对于交互式资源管理器,请查看apigee的salesforce控制台: https://apigee.com/console/salesforce For the REST API, you don't need to use the WSDL. You can explore the API by going to https://{instan ... -
作为这篇文章的更新,我能够找到错误。 Apex的索引从0开始而不是1(与MatLab不同,这是导致我混淆的原因)。 因为我从索引1开始,所以XML请求在第0个索引处传递'null'值,从而导致错误。 从0开始,从XML中删除了空值并且请求经历了。 As an update to this post, I was able to find the error. The indexing for Apex starts at 0 not 1 (unlike MatLab which is what caused ...
-
如何使用SOAP Partner API创建SalesForce“用户”?(How to create a SalesForce 'User' with SOAP Partner API?)[2022-04-07]
create调用返回一个错误,但你没有检查它,返回的SaveResult会告诉你为什么它没有创建用户,你想要的东西像 SaveResult[] results = connection.create(new SObject[] { user }); if (results[0].isSuccess()) System.out.println("Created user: " + results[0].getId()); else System.out.println("Error: " + ...