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

Trending Topics

Online now

Members online
373
Guests online
10,929
Total visitors
11,302

Forum statistics

Threads
2,369,781
Posts
29,451,201
Members
1,034,634
Latest member
bajsbosn
Back
Top