会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132462个问题
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/Zookeeper 34366楼
JAVA 全系列/第十一阶段:分布式RPC调用和分布式文件存储/FastDFS 34367楼
Python 全系列/第七阶段:网页编程基础/JavaScript 34368楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO流技术 34370楼

package com.bjsxt;

/**
 * 基于单向链表实现元素存取的容器
 * @param <E>
 */
public class MySinglyLinkedList<E> implements MyList<E> {
    /**
     * 定义单向链表中的节点对象
     */
    class Node<E>{
        private E item;//存储元素
        private Node next;//存储下一个节点对象的地址
        Node(E item,Node next){
            //传递过来的参数传递给成员变量
            this.item = item;
            this.next = next;
        }
    }
    private Node head;//存放链表中的头节点。
    private int size;//记录元素个数
    @Override
    /**
     * 向链表中添加元素
     */
    public void add(E element) {
        //创建节点
        Node<E> node = new Node<>(element,null);
        //找到未节点
        Node tail = getTail();
        //节点的挂接
        if (tail == null){
            this.head = node;
        }else{
            tail.next=node;
        }
        //记录元素个数
        this.size++;

    }

    /**
     *找到尾节点
     */
    private Node getTail(){
        //头节点是否存在
        if (this.head == null){
            return null;
        }
        //查找尾节点
        Node node = this.head;
        while (true){
            if (node == null){
                break;
            }
            node  = node.next;//移动指针,指向下一个节点
        }
        return node;
    }

    @Override
    /**
     * 根据元素的位置获取元素
     */
    public E get(int index) {
        //校检Index的合法性
        this.checkIndex(index);
        //根据位置获取指定的节点
        Node<E> node = this.getNode(index);
        //将该节点中的元素返回
        return node.item;
    }

    /**
     * 对Index进行校验
     * @return
     */
    private void checkIndex(int index){
        if (!(index >=0 && index < this.size)){
            throw new IndexOutOfBoundsException("Index:"+index+"Size"+this.size);

        }
    }

    /**
     *根据位置获取指定的节点
     * @return
     */
    private Node getNode(int index){
        Node<E> node = this.head;
        for(int i=0;i<index;i++){
            node = node.next;
        }
        return node;
    }

    @Override
    /**
     * 获取元素个数
     */
    public int size() {

        return this.size;
    }

    @Override
    /**
     * 根据元素的位置删除元素
     * @param index
     * @return
     */

    public E remove(int index) {
        //校验Index的合法性
        this.checkIndex(index);
        //根据位置找到该节点对象
        Node<E> node = this.getNode(index);
        //获取该节点对象中的元素
        E item = node.item;
        //将该节点对象从单向表中移除
            //判断当前删除的节点是否为头节点
        if(this.head == node ){
            this.head = node.next;
        }else{
            Node<E> temp = this.head;
            for (int i = 0;i<index-1;i++){
                temp = temp.next;
            }
            temp.next = node.next;
        }
        node.next = null;
        //记录元素个数、
        this.size--;
        //将该元素返回
        return item;
    }

    public static void main(String[] args) {
        MySinglyLinkedList<String> mySinglyLinkedList = new MySinglyLinkedList<>();
        mySinglyLinkedList.add("a");
        mySinglyLinkedList.add("b");
        mySinglyLinkedList.add("c");
        mySinglyLinkedList.add("d");
        System.out.println("size:"+mySinglyLinkedList.size());
        System.out.println("删除:"+mySinglyLinkedList.remove(0));
        for (int i =0;i<mySinglyLinkedList.size();i++){
            System.out.println(mySinglyLinkedList.get(i));

        }
    }
}
package com.bjsxt;

/**
 * 基于链表结构存取元素的方法 API 定义
 * @param <E>
 */
public interface MyList<E> {
    void add(E element);
    E get(int index);
    int size();
    E remove(int index);
}

运行效果图:

老师,1:我明明删除的是0索引,对应的应该是“a”才对怎么给我返回了个“d”啊,

2:我遍历的时候怎么给我报异常啊,明明是对着老师的代码敲的啊

image.png


JAVA 全系列/第二阶段:JAVA 基础深化和提高/数据结构 34371楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>cookie案例</title>
    <style>
        .loginRegistDiv{
            text-align: center;
            padding: 15px;
            border: 1px solid black;
            width: 300px;
            min-height: 30px;
        }
        .welcomeDiv{
            text-align: center;
            padding: 15px;
            border: 1px solid black;
            width: 300px;
            min-height: 30px;
            display: none;
        }
        .nickNameSpan{
            color: green;
            font-size: 22px;
            font-weight: bold;
        }
    </style>
</head>
<body>
 <div class="loginRegistDiv">
     <lable for="userName">
         <span>用户名:</span><input type="text" id="userName" placeholder="请输入用户名">
     </lable><br><br>
     <lable for="password">
         <span>密&nbsp;&nbsp;&nbsp;码:</span><input type="text" id="password" placeholder="请输入密码">
     </lable><br><br>
     <button class="loginBtn">登录</button>
     <button class="registBtn">注册</button>
 </div>
<div class="welcomeDiv">
    欢迎回来,尊敬的:
    <span class="nickNameSpan">哈哈哈</span>
    <br><br>
    <button class="exitBtn">注销登录</button>
</div>
 <script>
     //页面逻辑
     ;(function () {
         var loginBtn=document.querySelector('.loginBtn');
         var userNameInput=document.querySelector('#userName');
         var passwordInput=document.querySelector('#password');
         var welcomeDiv=document.querySelector('.welcomeDiv');
         var loginRegistDiv=document.querySelector('.loginRegistDiv');
         var nickNameSpan=document.querySelector('.nickNameSpan');
         var exitBtn=document.querySelector('.exitBtn');
         //表示一个自动登录的功能
         function getCookie() {
             var cookie=document.cookie;
             var cookieArr=cookie.split(';');
             // console.log(cookieArr);//得到的是数组 (2) ["uname=beixi", " userId=120123"]
             var finalObj={};
             for (var i=0;i<cookieArr.length;i++){
                 //trim()是去除空格
                 var tempArr=cookieArr[i].trim().split('=');
                 //console.log(tempArr);//(2) ["uname", "beixi"]  (2) ["userId", "120123"]
                 finalObj[tempArr[0]]=tempArr[1];
             }
             return finalObj;
         }
         console.log(getCookie());
         var cookieObj=getCookie();
         //判断cookie存储的nickName是否存在
         if (cookieObj.nickName!=undefined){
             if (cookieObj.nickName.length!=0){
                 loginRegistDiv.style.display='none';
                 welcomeDiv.style.display='block';
                 nickNameSpan.innerHTML=cookieObj.nickName;
             }
         }
         loginBtn.onclick=function () {
            //发送Ajax请求
             var xhr=new XMLHttpRequest();
             xhr.onreadystatechange=function () {
                 if (xhr.readyState==4){
                     if (xhr.status==200){
                         var data=xhr.responseText;
                         if (data.infoCode==0){
                             loginRegistDiv.style.display='none';
                             welcomeDiv.style.display='block';
                             nickNameSpan.innerHTML=data.nickName;
                         }
                     }
                 }
             };
             var formData=new FormData();
             formData.append('uname',userNameInput.value);
             formData.append('upass',passwordInput.value);
             xhr.open('post','7-cookie案例后台.php',true);
             xhr.send(formData);
         };
         //退出登录按钮
         exitBtn.onclick=function () {
             userNameInput.value='';
             passwordInput.value='';
             loginRegistDiv.style.display='block';
             welcomeDiv.style.display='none';
             //清除cookie
             var expires=new Date(new Date().getTime()+1).toGMTString();
             document.cookie='nickName=beixi,expires='+expires;
         }
     })();
 </script>
</body>
</html>

php:
 <?php
$success=array('msg'=>'ok');
$userName=$_POST['uname'];
$password=$_POST['upass'];
//连接数据库
try{
$con=new PDO('mysql:host=localhost;dbname=beixidb','root','');
   if($con){
      //添加辅助设置
      mysqli_query($con,'set names utf8');
      mysqli_query($con,'set character_set_client utf8');
      mysqli_query($con,'set character_set_results utf8');
      $sql="select * from userinfo where 1";
      $result=$con->query($sql);
      //解析查询的结果
      if($result->num_rows>0){
        $info=[];
        for($i=0;$row=$result->fetch_assoc();$i++){
          $info[$i]=$row;
        }
        //$success['infoCode']=$info;//拿到数据了
        //得到解析数组后,判断用户发来的内容是否存在于数据库中
        $flag=0;//只要执行break,就变为1,否则一直为0
        for($j=0;$j<count($info);$j++){
         //判断是否与当前条目的用户名相同
         if($info[$j]['username']==$username){
            //如果相同,继续判断是否是当前条目的密码
            if($info[$j]['password']==$password){
                $success['infoCode']=0;
                $flag=1;
                break;
            }
         }
        }
        if($flag==0){
        $success['infoCode']=1;
        }
      }else{
        $success['infoCode']=1;
      }
      }else{
      //向前台返回信息
      //0代表登录成功,1代表登录失败,2代表数据库连接失败
      $success['infoCode']=2;
      }
}catch(PDOException  $err){
echo '出现错误信息:'.$err->getMessage();
}
setcookie('nickName','beixi',time()+3600*24);
//回馈前端表示登录成功,使用状态码infoCode  0表示成功  1表示失败
$success['infoCode']=0;
$success['nickName']='beixi';
echo json_encode($success);
?>

老师,我总觉得我的优点问题,但是又找不到代码出错的地方,老师帮忙看看呗,谢谢老师

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 34372楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 34374楼

vue_shop.zip

后端接口写完了以后,前端页面菜单显示不出来  一片空白

image.png

Python 全系列/第十阶段:Flask百战电商后台项目/Flask百战电商后台项目 34375楼
JAVA 全系列/第十一阶段:智能家居项目(旧)/至尊智能家居第二天 34379楼
Python 全系列/第一阶段:Python入门/序列 34380楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637