首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

哪位高手可以帮小弟我个写个链表的算法?

2012-03-20 
谁可以帮我个写个链表的算法?????题目是 删除非循环单链表中数据域为e的第一个结点 要求用C++写还有用类模

谁可以帮我个写个链表的算法?????
题目是 删除非循环单链表中数据域为e的第一个结点 要求用C++写 还有用类模板 
template<class T> 还有给出主函数里面的函数调用 本人新手学数据结构 求各位大牛 帮助下菜鸟 谢谢

[解决办法]

C/C++ code
template<class T>struct Node{    T data;    Node *next;};template<class T>class Link{  public:    // 类其他部分的声明...    // 功能函数    int del(const T& t);private:    T *head; //带头结点的链表    // ... };//删除成功返回 0,失败返回 -1template<class T>int del(const T& e){    T *pre, *q;    pre = head;    q = head->next;    while(q){        if(q->data == e){            pre->next = q->next;            delete q;            return 0; // 找到并删除        }    }    return -1; //失败} 

热点排行