从发行链表中添加和删除节点 [英] Issue adding and deleting nodes from a linked list

查看:203
本文介绍了从发行链表中添加和删除节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了输入采取从文本文件的程序,创建一个链表与此输入,那么可以添加,删除,修改和查询链表。

我的查询和修改功能正常工作。一个特定的情况下下,我的删除功能失败,我与add函数挣扎。从编译器没有错误助阵。这将大大pciated如果任何人都可以在正确的方向指向我AP $ P $。

add函数是给我的最大问题。几个小时从同事的调试和帮助之后,最接近我已经得到了添加任何正在发生变化。

更新:谢谢大家的反馈!最后我发现我和同事的帮助具有重大课题。显然,我经过周围值,而不是引用。 **做的伎俩为添加和删除功能。

 无效添加(员工**头,诠释addEMP_ID,字符* addName,诠释addDept,诠释addRank,双addSalary){
}无效删除(员工**头,INT选项){
}


解决方案

有两件事情需要考虑。

开始一个伪OOP去,围绕一个指针传递给结构列表,而不是结构节点

  typedef结构structList {
    EmployeeData工作*头;
} EmployeeList的;

使用双指针迭代器的插入和删除。

I have a program that has to take in input from a text file, create a linked list with this input, then be able to add, delete, modify, and query the linked list.

My query and modify functions work fine. My delete function fails under a particular case, and I'm struggling with the add function. No errors from the compiler to help out. It would be greatly appreciated if anyone could point me in the right direction.

The add function is giving me the biggest problems. After a couple hours of debugging and help from a coworker, the closest I've gotten to adding anything is changing

UPDATED: Thanks everyone for the feedback! I ended up discovering the major issue I was having with the help of a co-worker. Apparently I was passing around a value instead of a reference. ** did the trick for both add and delete functions.

void add(employee **head, int addEMP_ID, char* addName, int addDept, int addRank, double addSalary) {
}

void delete(employee **head, int option) {
}

解决方案

Two things to consider.

Start a pseudo-OOP going, pass around a pointer to struct List rather than struct Node.

typedef struct structList {
    employeeData *head; 
}  EmployeeList;

Use the double-pointer iterator to insert and delete.

这篇关于从发行链表中添加和删除节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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