package com.Cx_330.run;
import org.junit.Test;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;
public class CCC {
public static void main(String[] args) {
SingleLinkedList singleLinkedList = new SingleLinkedList(new Student(-1, "", ""));
Student s1 = new Student(1, "张三", "女");
Student s2 = new Student(2, "张四", "男");
Student s3 = new Student(3, "张五", "女");
Student s4 = new Student(4, "张六", "男");
Student s5 = new Student(5, "张七", "女");
singleLinkedList.add2(s1);
singleLinkedList.add2(s5);
singleLinkedList.add2(s3);
singleLinkedList.add2(s4);
singleLinkedList.add2(s2);
//删除前
singleLinkedList.List();
//删除后
System.out.println("\n删除id为3后....");
singleLinkedList.delteById(singleLinkedList.getStudentHead(),3);
singleLinkedList.List();
//修改
System.out.println("\n修改id为2后....");
Student student = new Student(2, "孙松", "男");
singleLinkedList.update(singleLinkedList.getStudentHead(),student);
singleLinkedList.List();
//求长度
System.out.println("链表的长度为: "+singleLinkedList.length(singleLinkedList.getStudentHead()));
//删除倒数第3个元素
System.out.println("\n删除倒数第3个元素");
Java单链表增删改查---百度腾讯新浪面试题--全家桶--学到了就是赚到了
最新推荐文章于 2023-12-20 09:30:00 发布
本文详细讲解了Java中单链表的数据结构,并通过实例展示了如何进行增、删、改、查等基本操作,适合准备百度、腾讯、新浪等公司面试的程序员学习。掌握这些技巧将对你的面试大有裨益。
摘要由CSDN通过智能技术生成