# 实验五和六 线性结构之链表

1.链表练习，要求实现下列功能：

20， 17，23，1， 20， 18，10，1，16，23，49

int nZhangSan = 0; //初始化为 0.

2.链表练习，要求实现下列功能：

3.链表练习，要求实现下列功能：

4.在android上实现实验（1）和（2）

5.在android平台上实现实验（3)

1.链表练习，要求实现下列功能：

20， 17，23，1， 20， 18，10，1，16，23，49

int nZhangSan = 0; //初始化为 0.

import java.util.Scanner;

{

exp exp = new exp();

Scanner scanner = new Scanner(System.in);

System.out.println("输入你相应的学号、日期、时间三个数据");

String string = scanner.nextLine();

StringTokenizer stringTokenizer = new StringTokenizer(string);

for(int i = 0; i<string.length();i++)

{

while (stringTokenizer.hasMoreTokens())

{

String f = stringTokenizer.nextToken();

int num = Integer.parseInt(f);

}

}

}

System.out.println("打印出来所有元素：" + exp.toString() + "总数之和：" + exp.Size());

2.链表练习，要求实现下列功能：

public void insert( int data, int index)

{

NumberNode node = new NumberNode(data);

NumberNode current = list;

NumberNode precious = list;

while (s!= index)

{

precious = current;

current = current.next;

s++;

}

node.next = current;

precious.next = node;

s = 0;

nLudayue++;

}

public void delete(int num)

{

NumberNode node = new NumberNode(num);

NumberNode current, temp;

if(list.Num == num)

{

current = list.next;

list = current;

}

else

{

current = list;

while(current.next.Num != num)

current = current.next;

temp = current.next.next;

current.next = temp;

}

nLudayue --;

}

public String toString()

{

String result = "";

NumberNode current = list;

while (current != null)

{

result += current.Num + " ";

current = current.next;

}

return result;

}

3.链表练习，要求实现下列功能：

import java.util.Scanner;

import java.util.Select;

public void Select()

{

NumberNode current;

current = list;

int[] A = new int[nLudayue];

for(int i = 0; i < nLudayue; i++) {

A[i] = current.Num;

current = current.next;

}

int[] B = selectSort(A);

list = null;

int top2 = nLudayue;

for(int i =0;i< top2; i++){

int num = B[i];

}

}

public int[] selectSort(int[] list) {

int min;

int temp;

for (int index = 0; index < list.length - 1; index++) {

min = index;

for (int scan = index + 1; scan < list.length; scan++)

if (list[scan] - (list[min]) < 0)

min = scan;

temp = list[min];

list[min] = list[index];

list[index] = temp;

}

return list;

}

posted @ 2021-11-07 23:16  20202310肖衍豪  阅读(10)  评论(0编辑  收藏  举报