Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - To realize a single linked list with java programming, it is necessary to provide functions such as insertion, deletion, sorting and statistics, and the data in the linked list nodes are required to b
To realize a single linked list with java programming, it is necessary to provide functions such as insertion, deletion, sorting and statistics, and the data in the linked list nodes are required to b
To realize a single linked list with java programming, it is necessary to provide functions such as insertion, deletion, sorting and statistics, and the data in the linked list nodes are required to be integers. Public class link {

Node header = empty;

Node = empty;

Node newNode = null

public int Count = 0; //Statistical value

//Insert

public void AddNode(int t) {

NewNode = new node ();

if (head == null) {

head = newNode

} Otherwise {

Point = head;

while (point.next! = null) {

point = point.next

}

point.next = newNode

}

point = newNode

point . vlaue = t;

point.next = null

count++;

}

//Return value

public int GetValue(int i) {

if(head = = null | | I & lt; 0 | | i> count)

return-999999;

int n;

Node temperature = null

Point = head;

for(n = 0; n & lt= I; n++) {

Temp = point;

point = point.next

}

Return the temperature value;

}

//Delete

public void DeleteNode(int i) {

If (I<0 | | i> count) {

Return;

}

if (i == 0) {

head = head.next

} Otherwise {

int n = 0;

Point = head;

Node temperature = point;

for(n = 0; N< me; n++) {

Temp = point;

point = point.next

}

temp . next = point . next;

}

count-;

}

//sort

public void Sotr() {

For (node i = header; Me! = nulli = i.next) {

For (node j = i.next; j! = nullj = j.next) {

If (i.e. i.vlaue & gtj.vlaue) (

int t = I . vla UE;

I . vla UE = j . vla UE;

j . vla UE = t;

}

}

}

}

}

Class node {

int vlaue

Next node;

}