🔒 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
  • 672
    Views
  • 4
    Participants
Last reply from:
fireclouu

Trending Topics

Online now

Members online
644
Guests online
5,241
Total visitors
5,885

Forum statistics

Threads
2,353,939
Posts
29,381,507
Members
1,081,190
Latest member
ggv2026
Back
Top