Data structure and algorithm 17 table insertion sorting

Table insert sort

Randomly generate a set of numbers, sort them through the linked list, and then copy them to the array to improve efficiency

``````class Link
{
public long  ddata;
{
ddata = dd;
}
{
System.out.println(ddata + " ");

}
}
class SortedList
{
public SortedList()
{
first = null;
}
{
first = null;
}
public boolean Empty()
{
return (first == null);
}
{

while(current !=null&&k.ddata>current.ddata)
{
previous = current;
current = current.next;
}
if(previous == null)

first = k;
else
previous.next =k;
k.next = current;

}
{
first = first.next;
return temp;
}
public void displayList()
{
while(currrent != null)
{
currrent = currrent.next;
}
System.out.println(" ");
}
}
class ListInsertionApp
{
public static void main(String[] args)
{
int size = 10;
for(int j=0;j<size;j++)
{
int n = (int)(java.lang.Math.random()*99);
}
System.out.println("unsorted");
for(int j=0;j<size;j++)
{
System.out.println(" ");
for(int i=0;i<size;i++)
System.out.print("sorted");
for(int x=0;x<size;x++)
System.out.println(" ");
}
}
}``````

Bidirectional linked list: allow forward traversal and backward traversal

Disadvantages: each time you insert or delete a chain node, you need to refer to four chain nodes instead of two.

The following is the insertion function, which is divided into insertion from the chain header and insertion from the chain tail

``````class Link
{
public long ddata;
{
ddata = d;
}
{
System.out.println(ddata + " ");
}
}
{
{
first = null;
last = null;
}
public boolean isEmpty()
{
return first == null;
}
public void insertFirst(long dd)
{
if(isEmpty())
else

}
public void insertLast(long dd)
{
if(isEmpty())