设为首页  
联系我们  
加入收藏  
网页制作 冲浪宝典 图形图像 操作系统 软件教学 编程开发 认证考试 安全技术 站长专区 文学驿站 娱乐天地 游戏天地 办公软件
文章搜索
您的位置: 首页 >> 文章首页 >> 编程开发 >> 游戏开发 >> 《Windows游戏编程大师技巧》(第二版)第11章
精品推荐
游戏开发点击TOP10
·DirectX5.0最新游戏编程指南 DirectDraw教程篇 二、第一个DirectDraw实例
·用Excel编写小游戏
·五子棋的原代码
·游戏开发方面相关的电子书下载
·游戏文件系统的解决方案
·基于LOD的大规模真实感室外场景实时渲染技术的初步研究 part II&III
·用MFC构造DirectX应用框架
·游戏开发开门
·《Windows游戏编程大师技巧》(第二版)第11章
·DirectX8.1的DirectDraw7研究手记(三)
编程开发点击TOP10
·数字小键盘指法练习
·ASP.NET 程序中常用的三十三种代码
·用C语言编通讯录程序(初学者级别的)
·我写的Java学生成绩管理系统源代码
·CHK文件恢复工具
·Modem 常用AT指令集
·java笔试题
·异常java.sql.SQLException: Io exception:The Network Adapter could not establish connection
·单片机模拟I2C总线及24C02(I2C EEPROM)读写实例(源代码)
·C++经典电子书下载
精选专题

《Windows游戏编程大师技巧》(第二版)第11章

作者: 来源:网络文章 时间:2005-12-17 22:39:07

《Windows游戏编程大师技巧》(第二版)第11章(3) 下面是源代码:
void Traverse_List(NODE_PTR head)
{
// this function traverses the linked list and prints out
// each node

// test if head is null
if (head==NULL)
   {
   printf("\nLinked List is empty!");
   return;
   } // end if

// traverse while nodes
while (head!=NULL)
      {
      // visit the node, print it out, or whatever...
      printf("\nNode Data: id=%d", head->id);
      printf("\nage=%d,head->age);
      printf("\nname=%s\n",head->name);

      // advance to next node (simple!)
      head = head->next;
      }  // end while

print("\n");

} // end Traverse_List
很酷是不是?下一步,让我们看一看如何在链表中插入一个节点。

插入节点
插入节点的第一步是创建该节点。创建节点有两种方法:你可以将新的数据元素传递给插入函数,由该函数来构造一个新节点;或者先构造一个新节点,然后将它传递给插入函数。这两种方法在本质上是相同的。
此外,还有许多方法可以实现节点插入链表的操作。蛮横的做法是将要插入的节点插在链表的开头或结尾。如果你不关心链表中节点的顺序,这倒不失为一个便捷的方法。但如果想保持链表原来的排序,你就应当采用更聪明的插入算法,这样可以保证插入节点后的链表仍然保持升序或降序的顺序。这也可以让以后进行搜索时速度更快。
为简明起见,我举一个最简单的节点插入方法的例子,也就是将节点插在链表的末尾。其实按顺序的节点插入算法并不太复杂。首先要扫描整个链表,找出新节点所要插入的位置,然后将其插入。惟一的问题就是保证不要丢失任何指针和信息。
下面的源代码将一个新节点插入链表的尾部(比插入链表头部难度稍大)。注意一下特殊的情况,即空链表和只有一个元素的链表:
// Access the global head and tail to make code easier
// in real life, you might want to use ** pointers and
// modify head and tail in the function ???

NODE_PTR Insert_Node(int id, int age, char *name)
{
// this function inserts a node at the end of the list
NODE_PTR new_node = NULL;

// step 1: create the new node
new_node = (NODE_PTR)malloc(sizeof(NODE)); // in C++ use new operator

// fill in fields
new_node->id  = id;
new_node->age = age;
strcpy(new_node->name,name); // memory must be copied!

1.《Windows游戏编程大师技巧》(第二版)第11章(1)
2.《Windows游戏编程大师技巧》(第二版)第11章(2)
3.《Windows游戏编程大师技巧》(第二版)第11章(3)
4.《Windows游戏编程大师技巧》(第二版)第11章(4)
5.《Windows游戏编程大师技巧》(第二版)第11章(5)
6.《Windows游戏编程大师技巧》(第二版)第11章(6)
7.《Windows游戏编程大师技巧》(第二版)第11章(7)
8.《Windows游戏编程大师技巧》(第二版)第11章(8)
9.《Windows游戏编程大师技巧》(第二版)第11章(9)
10.《Windows游戏编程大师技巧》(第二版)第11章(10)
11.《Windows游戏编程大师技巧》(第二版)第11章(11)
12.《Windows游戏编程大师技巧》(第二版)第11章(12)
13.《Windows游戏编程大师技巧》(第二版)第11章(13)
14.《Windows游戏编程大师技巧》(第二版)第11章(14)
15.《Windows游戏编程大师技巧》(第二版)第11章(15)
16.《Windows游戏编程大师技巧》(第二版)第11章(16)
17.《Windows游戏编程大师技巧》(第二版)第11章(17)
18.《Windows游戏编程大师技巧》(第二版)第11章(18)
19.《Windows游戏编程大师技巧》(第二版)第11章(19)
20.《Windows游戏编程大师技巧》(第二版)第11章(20)
21.《Windows游戏编程大师技巧》(第二版)第11章(21)
22.《Windows游戏编程大师技巧》(第二版)第11章(22)
23.《Windows游戏编程大师技巧》(第二版)第11章(23)
24.《Windows游戏编程大师技巧》(第二版)第11章(24)
25.《Windows游戏编程大师技巧》(第二版)第11章(25)
26.《Windows游戏编程大师技巧》(第二版)第11章(26)
27.《Windows游戏编程大师技巧》(第二版)第11章(27)
28.《Windows游戏编程大师技巧》(第二版)第11章(28)
29.《Windows游戏编程大师技巧》(第二版)第11章(29)
30.《Windows游戏编程大师技巧》(第二版)第11章(30)
31.《Windows游戏编程大师技巧》(第二版)第11章(31)
32.《Windows游戏编程大师技巧》(第二版)第11章(32)
33.《Windows游戏编程大师技巧》(第二版)第11章(33)
34.《Windows游戏编程大师技巧》(第二版)第11章(34)
35.《Windows游戏编程大师技巧》(第二版)第11章(35)
36.《Windows游戏编程大师技巧》(第二版)第11章(36)
37.《Windows游戏编程大师技巧》(第二版)第11章(37)
38.《Windows游戏编程大师技巧》(第二版)第11章(38)
共38页 9 7 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [388 :>

《Windows游戏编程大师技巧》(第二版)第11章 相关文章:
《Windows游戏编程大师技巧》(第二版)第11章 相关软件:
特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
转载请注明来源:http://www.xgdown.com