算法设计手册,第3章,链表code段的混乱 [英] Algorithm Design Manual, chapter 3, linked-list code snippet confusion

查看:127
本文介绍了算法设计手册,第3章,链表code段的混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在读的算法设计手册,并在第三章中,将出现以下code段。它必须与从链接列表中删除的项。现在的问题是不相关的数据结构,而只是为code其中两个变量被宣布为单行的我觉得的。我已经剥离的code中的不相关的部分为简洁起见。

I'm reading the Algorithm Design Manual and in chapter 3, the following code snippet appears. It has to do with removing an item from a linked-list. The question isn't related to data-structures, but just to a single line of code where two variables are declared I think. I've stripped the non-relevant parts of the code for brevity.

list *search_list(list *l, item_type x) {
  // This function just searches the list x
}

list *predecessor_list(list *l, item_type x) {
  // This function simply returns the predecessor of x or NULL
}

delete_list(list **l, item_type x) {
  list *p;     /* item pointer */
  list *pred;  /* predecessor pointer */

  list *search_list(), *predecessor_list(); // What are these declarations?

  p = search_list(*l,x);

  // Code to delete the node if found is here    
}

我的问题是,在 delete_list功能,具体而言,该行列表* search_list(),* predecessor_list(); 。什么是发生在这条线?我猜这是一个指向函数的指针,但我的理解是,你都应该用适当的参数声明函数指针。另外,假设我是正确的,为什么这些线路甚至需要?

My question is in the delete_list function, specifically, the line list *search_list(), *predecessor_list();. What is happening on that line? I'm guessing it's a pointer to a function, but my understanding is you are supposed to declare the function pointer with the appropriate parameters. Also, assuming I am correct, why are those lines even needed?

推荐答案

在这行,

list *search_list(), *predecessor_list();

会通知标识符功能的存在以及它的返回类型是编译器。在这方面,数字和(多个)参数的函数需要是不需要的。的类型

informs the compiler that an identifier for a function exists and what its return type is. In this context, the number and type of parameter(s) the function requires is not needed.

我同意这是一个有点特殊,不是很直观,但是,C语言支持很多这样的特点。

I agree it's a bit peculiar and not very intuitive, however, the C language supports many such peculiarities.

达博所提供的评论你的问题的链接进入更多细节:<一href="http://stackoverflow.com/questions/5481579/whats-the-difference-between-function-prototype-and-declaration/5481685#5481685">What's函数原型和声明之间的区别是什么?

The link provided in a comment to your question by Dabo goes into more detail: What's the difference between function prototype and declaration?

这篇关于算法设计手册,第3章,链表code段的混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆