// parint(a)
/**
- 2.计算链表的长度
*/
//第一种
// var num = 0;
// function count(root){
// if(root){
// num++
// count(root.next)
// }
// }
// count(a)
// console.log(num)
// // 第二种
// function count(root) {
// if(!root) return 0;//表示没有节点
// return 1 + count(root.next) //1表示根节点占用的一个数量
// }
// console.log(count(b))
/**
-
3.得到链表某个下标的数据
-
@param {*} root
-
@param {*} index
*/
// function getValue(root,index) {
// //辅助函数
// function _getValue(node,i){
// //判断如果链表为空,终止查找
// if(!node) return null;
// if(i == index) return node.value;
// return _getValue(node.next,i+1)
// }
// //链表每次查询都要从头开始,然后可以递归每次加一,知道查询到
// return _getValue(root,0)
// }
// var result = getValue(a,2)
// console.log(result)
/**
*根节点 修改的链表数据的下标,要修改成的值
-
@param {*} root
-
@param {*} index
-
@param {*} value
*/
// function setValue(root,index,value){
// //辅助函数
// function _getValue(node,i){
// if(!node) return null;
// if(i == index) {
// node.value = value
// }else{
// _getValue(node.next,i+1)
// }
// }
// _getValue(root,0)
// }
// setValue(a,1,‘修改的值’)
// console.log(a)
// 在某个链表节点之后加入一个新节点
/**
*节点,新节点
-
@param {*} node
-
@param {*} newValue
*/
// function insertAfter(node,newValue){
// //先创建一个节点
// var newNode = new Node(newValue);
// node.next = newNode;
// newNode.next = node.next
// }
// insertAfter(b,“n”)
// console.log(a)
// 在链表结尾加入新节点
/**
-
@param {*} root
-
@param {*} newValue
*/
// function push(root,newValue) {
// //判断是最后一个节点
// if(!root.next){
// //最后一个节点
// var newNode = new Node(newValue)
// root.next = newNode;
// }
// else {
// push(root.next,newValue); //自己不是最后一个,看下一个
// }
// }
// push(a,‘m’)
// console.log(a)
/**
*根据给定的链表,和删除的值,删除对应的节点
-
@param {*} root
-
@param {*} nodeValue
*/
// function removeNode(root,nodeValue){
// if(!root || !root.next) return; // 无法删除的情况
// if(root.next.value === nodeValue) {
// //下一个节点就是要找的节点1
// root.next = root.next.next;
// }
// else {
// //下一个节点还不是
// removeNode(root.next,nodeValue)
// }
// }
文末
篇幅有限没有列举更多的前端面试题,小编把整理的前端大厂面试题PDF分享出来,一共有269页