Java資料結構之佇列(二)

2021-09-12 07:06:37 字數 1024 閱讀 6796

/**

* 迴圈佇列避免空間浪費 迴圈佇列不使用動態陣列,底層的動態陣列自己維護

* * @author zyw

* * @param */

public class loopqueueimplements myqueue

public loopqueue()

public int getcapacity()

@override

public void enqueue(e e)

data[tail] = e;

tail = (tail + 1) % data.length;

size++;

} private void resize(int capacity)

data = newdata;

front = 0;

tail = size;

} @override

public e dequeue()

e res = data[front];

data[front] = null;

front = (front + 1) % data.length;

size--;

if (size == getcapacity() / 4 && getcapacity() / 2 != 0)

return res;

} @override

public e getfront()

return data[front];

} @override

public int getsize()

@override

public boolean isempty()

/*** tosting方法與擴容方法的遍歷方式不一樣,兩種不同的遍歷方式

*/@override

public string tostring() else

} return res.tostring();

}}

資料結構 之佇列的java實現(二)

佇列的鏈式儲存結構簡稱為鏈佇列。它是限制僅在表頭刪除和表尾插入的單鏈表。鏈佇列 author wwx public class linkqueue public node t data,node next 佇列頭指標 private node front 佇列尾指標 private node rea...

資料結構之佇列(二) 鏈佇列

鏈佇列採用帶頭結點的鍊錶,隊頭指標始終指向頭結點,隊尾指標始終指向最後乙個元素 當隊列為空時 隊頭指標和隊尾指標均指向頭結點 鏈佇列不會滿!鏈佇列的定義 2.定義鏈佇列結構體 分別儲存兩個結點指標,隊頭指標和隊尾指標 typedef char datatype typedef struct node...

java資料結構 佇列

1.用鍊錶實現單向佇列 package com.jzm.stackqueuetree public class linkqueue end constructor private class node end constructor private t getdata private node ge...