正在加载图片...
Chapter 4 Data Structure 4.2 Stacks As another example of backtracking, suppose we want to print the names in a linked list in reverse order--that is last name first. Our problem is that the only way we can access the names is by following the linked structure. Thus we need a way of holding each name retrieved until all of the names that follow have been retrieved and printed. Our solution is to traverse the list from its beginning to its end while pushing the names we find onto a stack After reaching the end of the list, we print the names as we pop them off the stack 我们在来举另一个例子,假设反向输出一张链接表中的姓名,也就是把最 后一个名字第一个输出。问题是我们只能跟着链接结构访问姓名。因此, 我们需要一种方式,通过这种方式,我们可以保持每一个姓名能被检索, 直到排列在这个姓名之后的姓名被得到并输出。我们的方案是从链接表的 开始顺序遍历到结尾,与此同时把每一个姓名按照遍历顺序进栈。当到达 链接表的末尾后,我们通过出栈操作来输出姓名。 计算机专业英语 4-15Chapter 4 Data Structure 计算机专业英语 4-15 As another example of backtracking, suppose we want to print the names in a linked list in reverse order--that is, last name first. Our problem is that the only way we can access the names is by following the linked structure. Thus we need a way of holding each name retrieved until all of the names that follow have been retrieved and printed. Our solution is to traverse the list from its beginning to its end while pushing the names we find onto a stack. After reaching the end of the list, we print the names as we pop them off the stack. 我们在来举另一个例子,假设反向输出一张链接表中的姓名,也就是把最 后一个名字第一个输出。问题是我们只能跟着链接结构访问姓名。因此, 我们需要一种方式,通过这种方式,我们可以保持每一个姓名能被检索, 直到排列在这个姓名之后的姓名被得到并输出。我们的方案是从链接表的 开始顺序遍历到结尾,与此同时把每一个姓名按照遍历顺序进栈。当到达 链接表的末尾后,我们通过出栈操作来输出姓名。 4.2 Stacks
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有