Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 125 additions & 13 deletions group22/2622819383/Task1/LinkedList.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public Node insertAsSucc(Object data) {
* �Ѹ���������
* ��������Ϊ 3->7->10 , ���ú��Ϊ 10->7->3
*/
public void reverse(){

public void reverse(){
int times = theSize;
int index = 0;
while (0 < --times)
add(index++, removeLast());
}

/**
Expand All @@ -139,28 +142,57 @@ public void reverse(){
* ���list = 2->5->7->8->10 ,ɾ���Ժ��ֵΪ7,8,10

*/
public void removeFirstHalf(){

public void removeFirstHalf(){
int times = theSize / 2;
while (0 < times--)
removeFirst();
}

/**
* �ӵ�i��Ԫ�ؿ�ʼ�� ɾ��length ��Ԫ�� �� ע��i��0��ʼ
* @param i
* @param length
*/
public void remove(int i, int length){
public void remove(int i, int length){
Node head = get(i).pred(); //ɾ��(head, tail)֮��Ԫ�� ɾ��[i, i + length - 1]֮��Ԫ��
Node tail = get(i + length - 1).succ();

head.succ = tail;
tail.pred = head;
theSize -= length;
}
/**
* �ٶ���ǰ������list���������������е�����
* �ӵ�ǰ������ȡ����Щlist��ָ����Ԫ��
* ���統ǰ���� = 11->101->201->301->401->501->601->701
* listB = 1->3->4->6
* list = 1->3->4->6
* ���صĽ��Ӧ����[101,301,401,601]
* @param list
*/
public static int[] getElements(LinkedList list){
return null;
public int[] getElements(LinkedList list){
Iterator itSelf = iterator();
Iterator itList = list.iterator();
int[] ret = new int[list.size()];

int i = 0; //list��Ԫ�ص�ֵ��������ǰ�б���Ҫȡ��Ԫ�ص���
lastI = 0;//��һ��ȡ��Ԫ�ص���
moveTimes = 0;
value = itSelf.next();
index = 0;//Ҫ���ص�������Ԫ�ص���

while (itList.hasNext()) {
i = itList.next();
if (theSize <= i) throw new IndexOutOfBoundsException();

moveTimes = i - lastI;
while (0 < moveTimes--)
value = itSelf.next();

ret[index++] = value;
lastI = i;
}

return ret;
}

/**
Expand All @@ -169,17 +201,58 @@ public static int[] getElements(LinkedList list){

* @param list
*/
//������e��ȵ�Ԫ�ص��ȣ��������ʧ���򷵻�-1
private int find(Object e) {
Iterator it = iterator();
int i = -1; //Ҫ���ص�Ԫ�ص���
Object value = null;

while (it.hasNext()) {
value = it.next();
i++;
if (value == e) return i;
if (e < value) return -1;
}

public void subtract(LinkedList list){

return -1;
}

public void subtract(LinkedList list){
Iterator it = list.iterator();
Object value = null;
int i = -1;

while (it.hasNext()) {
value = it.next();
i = find(value);

//ɾȥ�ظ�Ԫ��
while (0 <= i) {
remove(i);
i = find(value);
}
}
}

/**
* ��֪��ǰ�����е�Ԫ����ֵ�����������У����Ե��������洢�ṹ��
* ɾ����������ֵ��ͬ�Ķ���Ԫ�أ�ʹ�ò���������Ա�������Ԫ�ص�ֵ������ͬ��
*/
public void removeDuplicateValues(){

Node current = header.succ();
Node next = current;
int removedNum = 0;

while ((next = next.succ()) != trailer) {
if (current.data() == next.data()) {
removedNum++;
} else {
current.succ = next;
next.pred = current;
current = next;
}
}
theSize -= removedNum;
}

/**
Expand All @@ -188,7 +261,26 @@ public void removeDuplicateValues(){
* @param min
* @param max
*/
//[low, min]U[max, end]


public void removeRange(int min, int max){
//ɾȥ(i, j]
int i = 0, j = 0;
Iterator it = iterator();
while (it.hasNext()) {
Object value = it.next();
if (value <= min) i++;
if (value < max) j++;
else break; //if(max <= value) break;
}

Node head = get(i);
Node tail = get(j).succ();

head.succ = tail;
tail.pred = head;
theSize -= (j - i);

}

Expand All @@ -197,7 +289,27 @@ public void removeRange(int min, int max){
* ��Ҫ������������C����Ԫ��Ϊ��ǰ������list��Ԫ�صĽ������ұ�C�е�Ԫ������ֵ������������
* @param list
*/
public LinkedList intersection( LinkedList list){
return null;
//����������A������B��Ԫ�صĺϼ�
public LinkedList intersection(LinkedList list){
LinkedList ret = new LinkedList();
Iterator it = iterator();
Iterator itList = list.iterator();
Object value1 = null, value2 = null;

if (it.hasNext() && itList.hasNext()) {
value1 = it.next();
value2 = itList.next();
}

while (value1 != null && value2 != null) {
if (value1 < value2) value1 = it.hasNext() ? it.next() : null;
else if (value2 < value1) value2 = itList.hasNext() ? itList.next() : null;
else {
ret.add(value1);
value1 = it.hasNext() ? it.next() : null;
value2 = itList.hasNext() ? itList.next() : null;
}
}
return ret;
}
}
125 changes: 0 additions & 125 deletions group22/2622819383/Task2/litestruts/Struts2实战.txt

This file was deleted.

Loading