You are viewing a single comment's thread. Return to all comments →
typescript boilerplate:
`use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8"); let inputString: string = ""; let inputLines: string[] = []; let currentLine: number = 0; process.stdin.on("data", function (inputStdin: string): void { inputString += inputStdin; });
process.stdin.on("end", function (): void { inputLines = inputString.split("\n"); inputString = ""; main(); });
function readLine(): string { return inputLines[currentLine++]; }
class stackQueue { private s1: number[] = []; private s2: number[] = [];
constructor() { this.s1 = []; this.s2 = []; }
enqueue(x: number) { // Enter your code here }
dequeue() { // Enter your code here }
print() { // Enter your code here } }
function main() { const testQueue = new stackQueue(); const commandMap = { "1": "enqueue", "2": "dequeue", "3": "print" } as const;
inputLines.shift();
inputLines.map((inputLine: string) => { const [command, input] = inputLine.split(" ") as ["1" | "2" | "3", string]; const method = commandMap[command]; if (method == "enqueue") { return testQueue.enqueue(Number(input)); } return testQueuemethod; }); }
`
javascript boilerplate "use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8"); let inputString = ""; let inputLines = []; let currentLine = 0; process.stdin.on("data", function (inputStdin) { inputString += inputStdin; });
process.stdin.on("end", function () { inputLines = inputString.split("\n"); inputString = ""; main(); });
function readLine() { return inputLines[currentLine++]; }
class stackQueue { constructor() { this.s1 = []; this.s2 = []; }
enqueue(x) { // Enter your code here }
function main() { const testQueue = new stackQueue(); const commandMap = { 1: "enqueue", 2: "dequeue", 3: "print" };
inputLines.map((inputLine) => { const [command, input] = inputLine.split(" "); const method = commandMap[command]; if (method == "enqueue") { return testQueue.enqueue(Number(input)); } return testQueuemethod; }); }
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
typescript boilerplate:
`use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8"); let inputString: string = ""; let inputLines: string[] = []; let currentLine: number = 0; process.stdin.on("data", function (inputStdin: string): void { inputString += inputStdin; });
process.stdin.on("end", function (): void { inputLines = inputString.split("\n"); inputString = ""; main(); });
function readLine(): string { return inputLines[currentLine++]; }
class stackQueue { private s1: number[] = []; private s2: number[] = [];
constructor() { this.s1 = []; this.s2 = []; }
enqueue(x: number) { // Enter your code here }
dequeue() { // Enter your code here }
print() { // Enter your code here } }
function main() { const testQueue = new stackQueue(); const commandMap = { "1": "enqueue", "2": "dequeue", "3": "print" } as const;
inputLines.shift();
inputLines.map((inputLine: string) => { const [command, input] = inputLine.split(" ") as ["1" | "2" | "3", string]; const method = commandMap[command]; if (method == "enqueue") { return testQueue.enqueue(Number(input)); } return testQueuemethod; }); }
`
javascript boilerplate "use strict";
process.stdin.resume(); process.stdin.setEncoding("utf-8"); let inputString = ""; let inputLines = []; let currentLine = 0; process.stdin.on("data", function (inputStdin) { inputString += inputStdin; });
process.stdin.on("end", function () { inputLines = inputString.split("\n"); inputString = ""; main(); });
function readLine() { return inputLines[currentLine++]; }
class stackQueue { constructor() { this.s1 = []; this.s2 = []; }
enqueue(x) { // Enter your code here }
dequeue() { // Enter your code here }
print() { // Enter your code here } }
function main() { const testQueue = new stackQueue(); const commandMap = { 1: "enqueue", 2: "dequeue", 3: "print" };
inputLines.shift();
inputLines.map((inputLine) => { const [command, input] = inputLine.split(" "); const method = commandMap[command]; if (method == "enqueue") { return testQueue.enqueue(Number(input)); } return testQueuemethod; }); }
`