ilength in C

[复制链接]
查看11 | 回复0 | 2010-2-11 02:54:54 | 显示全部楼层 |阅读模式
In order to remove the loop, you have to add a variable, so that real-time updated list length. :)------ list.h ------struct ilist_node;struct ilist_type; // add a new structtypedef struct ilist_type ilist;ilist icons(int, ilist);int ifirst(ilist);ilist irest(ilist);ilist iempty();int iempty_huh(ilist);void idelete(ilist); int ilength(ilist);------ list.c ------#include "ilist.h"#include // The ilist ADT is a pointer to this secret structstruct ilist_node { struct ilist_node * rest; int first;};struct ilist_type { struct ilist_node inode; int length; // update it when add new nodes or delete them.}// all the "ilist->" need to be changed into "ilist.inode->"......int ilength(ilist il){return il.length;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行