数据结构42-链表indexOf方法实现

 LinkList.prototype.get = function (data) {
          var current = this.head;
          var index = 0;
          //开始查找
          while (current) {
            if (current.data == data) {
              return index;
            }
            current = current.next;
            index += 1;
          }
          return -1;
        };

posted @ 2022-12-13 14:58  前端导师歌谣  阅读(22)  评论(0)    收藏  举报