資料結構(棧和佇列)

2022-09-13 09:09:11 字數 1401 閱讀 7239

題目一:棧的壓入和彈出順序

static

bool ispoporder(int order, int

poporder)

if (order.length == 1 && order[0] == poporder[0

])

stack.push(order[currentorderindex]);

//將原始序列第乙個值壓棧

currentorderindex++; //

指標指向後一位。

while (currentorderindex <= order.length) //

原始序列的當前指標沒有指向最後則一直迴圈

//加等號是為了讓迴圈繼續,因為最後被加入stack裡的值,還沒有機會pop出來

//如果不相等,則

if (currentorderindex currentorderindex++; //

原始序列指標向後移動

}

if (stack.count == 0

)

return

false

; }

題目二:

設計包含min函式的棧[資料結構]  

public

class

withminstack

public

void push(int

value)

}public

intpop()

return

popvalue;

}public

intmin()

}

題目三: 用兩個佇列實現棧

public

class customstack

public

void

push(t value)

public

t pop()

return

queue2.dequeue();

}else

return

queue1.dequeue();}}

}

題目四: 用兩個棧實現佇列

public

class customqueue

public

void

enqueue(t item)

public

t deque()

}count = count - 1

;

return

secondstack.pop();

}public

int count

}

資料結構 棧和佇列

棧 基礎 知識棧 練習題 佇列 基礎知識 棧示意圖 後進先出 順序棧結構定義 define maxsize 1024 struct stack 操作函式 push 入棧 pop 出棧 struct lstack 鏈棧示意圖 操作函式 push 入棧 pop 出棧 注意 也可以直接呼叫系統已經寫好的庫...

資料結構 棧和佇列

本章的基本內容是 兩種特殊的線性表 棧和佇列 從資料結構角度看,棧和佇列是操作受限的線性表,他們的邏輯結構相同。從抽象資料型別角度看,棧和佇列是兩種重要的抽象資料型別。p棧 限定僅在表的一端進行插入和刪除操作的線性表。p允許插入和刪除的一端稱為棧頂,另一端稱為棧底。p空棧 不含任何資料元素的棧。a ...

資料結構 棧和佇列

用兩個棧來實現乙個佇列,完成佇列的push和pop操作。佇列中的元素為int型別。class solution int pop node stack2.top stack2.pop return node private stack stack1 stack stack2 大家都知道斐波那契數列,現...