[英]How to find max element of a doubly linked list?
After reading the data from a file in a double-linked list I must determine the maximum of the this data.从双链表中的文件读取数据后,我必须确定该数据的最大值。 This topic is new to me so I need some help.
这个话题对我来说是新的,所以我需要一些帮助。 This is what i have:
这就是我所拥有的:
struct node {
int info;
node *next, *back;
};
node *cap = NULL;
node *first, *last, *c, *q;
Iterate over the list and store the max like this:遍历列表并像这样存储最大值:
node *max = first;
while (first) {
if (max->info < first->info)
max = first;
first = first->next;
}
This assumes that next
is null pointer when the element is the last one.这假设当元素是最后一个时,
next
是 null 指针。
What are *c and *q for? *c 和 *q 是干什么用的?
Also, if you can already traverse the list, just create a max node and update it while traversing另外,如果您已经可以遍历列表,只需创建一个最大节点并在遍历时更新它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.