23.1k views
1 vote
If we compare the push function of the stack with the insertFirst function for general lists, we see that the algorithms to implement these operations are similar.

True

False

User Ebassi
by
5.5k points

1 Answer

4 votes

Answer:

True

Step-by-step explanation:

Algorithm for push function

The method of placing data on a stack is called a push operation.

It involves these steps −

  • Check that the stack is complete.
  • If the stack is complete, it will cause an error .
  • Increases top to point next empty room if the stack is not complete.
  • Adds the data component to the place of the stack where top is pointing.
  • Success returns.

Algorithm for Insertfirst function

  • Create a new Link with provided data.
  • Point New Link to old First Link.
  • Point First Link to this New Link.

As we can see that in both algorithms ,we are inserting data to a new nodes and incrementing/pointing to a new node for inserting data.Both algorithms uses the same approach.

User Epifanio
by
5.7k points