🔒 Closed Need help with Data Structure

Status
Not open for further replies.

unknownusers25

Journeyman
Paano po ba i-implement ang change function sa Stack at Queue? Wala po akong mahanap na info about sa operation na change sa Queue at Stack. Salamat sa sasagot.
 
Stack - Last in First Out
change by push, or pop, stack pointer (SP) points to previous stack

Queue - First In First Out
literal na pila, serve who comes first unlike stack na serve whats on the current SP then inc/decrement pointer

sa change... idk?

Code:
// STACK
let exampleStack[size]
let sp = 0; // stack pointer

doStack(let push, let value)
  if (push)
   exampleStack[sp++] = value;
  else
   return exampleStack[--sp];


// Queue
let exQueue[size]
let qt = 0; // queue tracking
doQueue(let add, let value)
  if (add)
   qMoveValueByOne(1) // right
   exQueue[0] = value
  else
   let tmp = exQueue[0]
   qMoveValueByOne(0) // left
   return tmp

baka mali ito, or iba tinutukoy sa class ninyo
 
Stack - Last in First Out
change by push, or pop, stack pointer (SP) points to previous stack

Queue - First In First Out
literal na pila, serve who comes first unlike stack na serve whats on the current SP then inc/decrement pointer

sa change... idk?

Code:
// STACK
let exampleStack[size]
let sp = 0; // stack pointer

doStack(let push, let value)
  if (push)
   exampleStack[sp++] = value;
  else
   return exampleStack[--sp];


// Queue
let exQueue[size]
let qt = 0; // queue tracking
doQueue(let add, let value)
  if (add)
   qMoveValueByOne(1) // right
   exQueue[0] = value
  else
   let tmp = exQueue[0]
   qMoveValueByOne(0) // left
   return tmp

baka mali ito, or iba tinutukoy sa class ninyo
Same po na kung ano ang gamit ng peak() operation, di ko lang magets yung sinabi na change() operation. By the way salamat po <3
 
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 647
    Views
  • 4
    Participants
Last reply from:
fireclouu

Trending Topics

Online now

Members online
1,055
Guests online
953
Total visitors
2,008

Forum statistics

Threads
2,274,917
Posts
28,959,318
Members
1,233,485
Latest member
senpaikatzu_88
Back
Top