c 寫個動態擴容順序棧

2021-08-28 20:27:24 字數 1112 閱讀 8667

兩倍擴容機制,泛型設計,有測試**

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.threading.tasks;

//動態擴容順序棧

/* *當棧滿時,兩倍擴容

*/namespace 順序棧

public int capacity

public arraystack()

public arraystack(int capacity)

public arraystack(t items)

public t pop()

count--;

return items[count];

}public void push(t data)

else if(count == capacity)

items[i] = data;

count++;

capacity = 2 * capacity;

}else}}

class program

,", stack.count, stack.capacity);

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第乙個");

stack.push("第不知道多少個");

console.writeline(" ",stack.count, stack.capacity);

str = stack.pop();

console.writeline(str);}}

}

棧(順序棧,多棧共享技術,動態順序棧,鏈棧)

include include define stacksize 10 建立 typedef struct seqstack seqstack 初始化 void initstack seqstack s 入棧 int push seqstack s,int elem s top s elem s t...

棧 順序棧(C )

棧是只允許在一端進行插入或刪除操作的線性表。假設某個棧s a1 a2 a3 a4 a5 a1為棧底元素,a5為棧頂元素。由於棧只能在棧頂進行插入和刪除操作,進棧次序為a1 a2 a3 a4 a5出棧順序為a5 a4 a3 a2 a1,所以棧的操作特性是後進先出 lifo 如果有n個不同元素進棧,出棧...

動態順序表(可擴容)的基本操作

標頭檔案 define crt secure no warnings 1 ifndef staticseqlist h define staticseqlist h include include include include include define maxsize 10 define ca...