Question
ADA question: I am trying to make: the function Top (S : Stack) return Item_Type, which returns the top item on the stack or raises
ADA question:
I am trying to make: the function Top (S : Stack) return Item_Type, which returns the top item
on the stack or raises the Underflow exception, to the generic unbounded stack package.
Current Code:
--start of code
package body Unbound_Stack is type Cell is record Item : Item_Type; Next : Stack; end record; procedure Push (Item : in Item_Type; Onto : in out Stack) is begin Onto := new Cell'(Item => Item, Next => Onto); end Push; procedure Pop (Item : out Item_Type; From : in out Stack) is begin if Is_Empty(From) then raise Underflow; else Item := From.Item; From := From.Next; end if; end Pop; function Is_Empty (S : Stack) return Boolean is begin return S = null; end Is_Empty; --added function Top (S : Stack) return Item_Type is begin --Raise the underflow if Is_Empty(S) then raise Underflow; else --or return top item from the stack, call pop Pop (Item_Type, from => S); end if; return tem_Type; end Top; end Unbound_Stack; --end of code
current error:
Builder results (3 items) D unbound_stack.adb (3 items) invalid use of subtype mark in expression or call 35:15 35:34 actual for "From" must be a variable 37:14"tem_Type" is undefined Builder results (3 items) D unbound_stack.adb (3 items) invalid use of subtype mark in expression or call 35:15 35:34 actual for "From" must be a variable 37:14"tem_Type" is undefined
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started