|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 猪猪虾 于 2022-3-17 15:05 编辑
本帖最后由 jhq999 于 2022-3-17 15:58 编辑
- void HeadInsert(struct Node** Ptable)///////主函数传进来的* Ptable=NULL;
- {
- //头插法:永远将数据插入链表的头部,称为头插法
- struct Node* temp;
- struct Node* node = new Node;
- if (node == NULL)
- {
- printf("failed to distribute memory....\n");
- exit(1);
- }
- getInput(node);
- if (*Ptable != NULL) //判断传进来的单链表是不是空的,即判断第第一个节点的地址是不是空的
- {
- temp = *Ptable;
- *Ptable = node;
- node->next = temp;
- }
- }
- int main()
- {
- struct Node* Table[Size];
- struct Book* ptr = NULL;
- initialTable(Table);//Node指针数组Table所有的指针初始化成NULL
- HeadInsert(Table);//*Table=NULL传进去的也是NULL
- PrintTable(*Table);
- //Table 的定义是 struct Node* Table[Size];
- //这是一个指针数组,实际上与 struct Node** 是相同的数据类型
- //是一个指针数组,存放的是 struct Node* 类型的指针
- // Table 作为数组名同时也是数组的首地址,而它存放的的是struct Node* 的地址
- ReleaseTable(Table); //* Table[]是指针数组,存放的是指针,Table指代的第一个元素的地址
- return 0;
- }
复制代码
|
|