栗子: # 题目:将一个数组逆序输出. # # 程序分析:用第一个与最后一个交换. import random list =[random.randint(0,100) for _ in range(21)] print(list) #数应该先排序 def bubbleSort(arr): for i in range(1, len(arr)): for j in range(0, len(arr)-i): if arr[j] > arr[j+1]: arr[j], arr[j + 1] = a
代码: package com.wangzhu.linkedlist; public class LinkedListDemo { /** * @param args */ public static void main(String[] args) { LinkedList linkedList = new LinkedList(); Node head = null; Node reverseHead = null; // 链表长度为0 head = new Node(); for (int
public class LinkedListRevert { public static void main(String[] args) { Node next3 = new Node(4,null); Node next2 = new Node(3,next3); Node next = new Node(2,next2); Node head =new Node(1,next); Node tmp = head; // 保存首节点 while (head!=null){ System.o