Homework (make up)

Homework (make up)

Summary of relevant knowledge points

sort

In the program, it is often encountered that the linked list needs to be sorted according to a certain size relationship. CollectionThe class methods provided by the class for sorting and searching are as follows:

public static sort(List<E> list)---- Arrange the elements in the list in ascending order

int binarySearch(List<T> list,T key,CompareTo<T> c)---Use the halved search method to find whether the list contains elements equal to the parameter key.

  • There is source code of a class, sort a member variable, let the class implement the Comparableinterface, and callCollection.sort(List)
  • There is no source code of the class, or multiple sorting, create a new class, and implement the Comparatorinterface callCollection.sort(List, Compatator)

Single list

Data structure: basic operations of singly linked list

The basic operations involving singly linked lists are as follows:

  • int initList(linkList *); Initialize a singly linked list with head pointer, head node, head node->next=NULL;
  • int createListHead(linkList *, int n); The head insertion method creates a linked list, the length of the linked list is n;
  • int createListTail(linkList *, int n); The tail insertion method creates a linked list, and the length of the linked list is n;
  • int getlength(linkList *); Get the length of the singly linked list;
  • int printList(linkList *); prints the entire linked list;
  • int getElem(linkList ,int i,ElemType ); Get the data element of the node at the i-th position in the linked list;
  • int insertList(linkList *, int i, ElemType data); Insert a node at the specified position (node ​​i) of the linked list, the range of i is 1~length (total length of the linked list);
  • int insertListTail(linkList *, ElemType data); Append a node to the linked list and add it at the end;
  • int deleteList(linkList , int i, ElemType data); Delete the node at the specified position (node ​​i), the range of i is 1~length (total length of the linked list);
  • int clearList(linkList *); delete the entire linked list, make the head node->next=NULL;

Make up the content of the class, screenshot of the result

1. Sort

针对下面的Student类,使用Comparator编程完成以下功能:
1. 在测试类StudentTest中新建学生列表,包括自己和学号前后各两名学生,共5名学生,给出运行结果(排序前,排序后)
2. 对这5名同学分别用学号和总成绩进行增序排序,提交两个Comparator的代码

1525601358961

2. Singly linked list

public class MyList {
    public static void main(String [] args) {
        //选用合适的构造方法,用你学号前后各两名同学的学号创建四个结点
        
        
        //把上面四个节点连成一个没有头结点的单链表
        
        //遍历单链表,打印每个结点的

        //把你自己插入到合适的位置(学号升序)

        //遍历单链表,打印每个结点的

        //从链表中删除自己

        //遍历单链表,打印每个结点的
    }
}

1525601755873

Programming topics in Chapter 15 of the textbook

(1) Use the stack structure to output several items of an, where an=2an-1+2an-2, a1=3, a2=8

1525602907012

(2) Write a program to store the students' English transcripts in the linked list into a tree set, so that the program is automatically sorted and the sorting results are output

1525603340546

(3) There are 10 U disks with two important attributes: price and capacity. Write an application that makes TreeMap

1525603631052

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325412931&siteId=291194637