如何修改c++链表中的数据3

How To Modify Data In a c++ Linked List 3

本文关键字:链表 数据 c++ 何修改 修改      更新时间:2023-10-16

我已经为插入创建了编码,并为图书馆系统搜索书籍,但现在我被困在如何更新我插入的书籍详细信息上?

    void Node::insert(char *barcode,char *title,char *author,char *quantity,char *price)
{
    daftar *newnode=NULL;
    newnode=new daftar(barcode,title,author,quantity,price);
    if(head==NULL)
    {
        head=newnode;
    }
    else
    {
        newnode->setnext(head);
        head=newnode;
    }
}

试试类似的、使用链接列表的基本方法。

void Node::update(char *barcode,char *title,char *author,char *quantity,char *price)
{
    Node* tmp = new Node();
    tmp = head;
    while(tmp != NULL)
    {
       if(strcmp(tmp->title,title) == 0)
       {
        tmp->barcode = barcode;
        tmp->author = author;
        tmp->quantity = quantity;
        tmp->price = price;
        return;
       } 
      else
        tmp = tmp->next;
     }
}