Java算法与数据结构代码

第1题:我给你搭建算法框架,具体需求,你只需往里面写Code即可:public class Program {private static final int N=6;public static void main(String[] args) {Node head=new Node(-1,null); // 定义头指针,带头结点的单链表 for(int i=0;i
Java算法与数据结构代码
第1题:我给你搭建算法框架,具体需求,你只需往里面写Code即可:
public class Program {private static final int N=6;public static void main(String[] args) {Node head=new Node(-1,null); // 定义头指针,带头结点的单链表 for(int i=0;i<N;i++){ Node e=new Node(i+1,null); tailInsert(head, e); } // Test Node p=head; while(p.getNext()!=null){ p=p.getNext(); }}/** * @param head 实施尾插法算法的单链表头指针 * @param e 所需的元素 */private static void tailInsert(Node head,Node e){Node p=head;while(p.getNext()!=null){p=p.getNext();// 寻访单链表,直至到达单链表末尾}// 实施尾插法p.setNext(e);}}class Node{private int id; // 编号private Node next; // 单链表后继指针private String vote;// 选票 public Node(){}public Node(int id, Node next) {super();this.id = id;this.next = next;}public Node(int id, Node next, String vote) {super();this.id = id;this.next = next;this.vote = vote;}@Overridepublic String toString() {return "Node [id=" + id + ", next=" + next + "]";}public int getId() {return id;}public void setId(int id) {this.id = id;}public Node getNext() {return next;}public void setNext(Node next) {this.next = next;}}第2题:参看我以前的回答:https://zhidao.baidu.com/question/431512924412893084
算法思想已经写的清楚得不能在清楚了。转成Java就是小菜一碟。
2017-03-20
这种问题你在这出1000可能都没人给你做,去其它的社区吧2017-03-20
mengvlog 阅读 8 次 更新于 2025-07-19 07:59:36 我来答关注问题0
  • 第1题:我给你搭建算法框架,具体需求,你只需往里面写Code即可:public class Program {private static final int N=6;public static void main(String[] args) {Node head=new Node(-1,null); // 定义头指针,带头结点的单链表 for(int i=0;i

  • 冒泡排序是比较经典的排序算法。代码如下:for(int i=1;i

  •  文暄生活科普 【数据结构与算法】通俗理解数组删除元素|双指针法|+实例代码

    在编程中,数组是连续内存空间上相同类型数据的集合,通过下标可以方便获取元素。当需要移除数组元素时,常规方法是遍历数组,覆盖目标位置的值。但是,这并不意味着删除了元素,实际上只是将该位置的数据替换成新值。当涉及到多维数组,如二维数组,Java并不会直接提供指针来访问元素地址,因此无法进行直接的...

  • 二叉树 1 2 34 5 6 7这个二叉树的深度是3,树的深度是最大结点所在的层,这里是3.应该计算所有结点层数,选择最大的那个。根据上面的二叉树代码,递归过程是:f(1)=f(2)+1 > f(3) +1 ? f(2) + 1 : f(3) +1 f(2) 跟f(3)计算类似上面,要计算左右结点,然后取大...

  •  dllgdx_2000 关于JAVA和数据结构的问题

    编程语言大同小异,基本的逻辑操作都是一样的。比如与或,if,while这些。但是java是面向对象,c是面向程序。我先学的c,后学的java,怎么都转不过来。现在习惯用java了,又不会用c了。其实吧,没必要学c。如果你java学的好,那么一般的函数调用,参数传递和逻辑语句都应该会了吧。这样接触一门新的...

檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部