Use of Stack Data Structure

What kind of data calls for the use of a Stack?

Page 1 of 1

8 Replies - 5499 Views - Last Post: 03 January 2010 - 01:49 PM

#1 Delta_Echo  Icon User is offline

  • D.I.C Addict

Reputation: 5
  • View blog
  • Posts: 722
  • Joined: 24-October 07

Use of Stack Data Structure

Posted 23 December 2009 - 03:40 PM

I read the tutorial on Data Structures written by born2code (good tutorial), however it didn't really elaborate on the actual use of Stacks. What kind of data is traditionaly stored in a Stack?

(Im not sure if this thread belongs here, but since it isn't directly related to any specific language I elected to place it here)
Is This A Good Question/Topic? 0
  • +

Replies To: Use of Stack Data Structure

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Use of Stack Data Structure

Posted 23 December 2009 - 03:52 PM

Build an infix to prefix converter. Then you might get some insight.
Was This Post Helpful? 0
  • +
  • -

#3 radamanthys  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 30-October 09

Re: Use of Stack Data Structure

Posted 27 December 2009 - 04:31 PM

IIRC compilers use stacks when checking things like if/else
Was This Post Helpful? 0
  • +
  • -

#4 GenHornet18  Icon User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • Posts: 629
  • Joined: 19-October 09

Re: Use of Stack Data Structure

Posted 27 December 2009 - 04:38 PM

hmm... I don't know the proper usage of them, or particularity what the stack was originally designed for, but the only language I have used it in is assembly and that's just for gaining more space to hold data when I enter or exit a subroutine or need a place to dump some stuff when I need the main registers. It's just another data structure, which (as they all do) have their place and purpose.
Was This Post Helpful? 0
  • +
  • -

#5 Programmist  Icon User is offline

  • CTO
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,833
  • Joined: 02-January 06

Re: Use of Stack Data Structure

Posted 27 December 2009 - 06:21 PM

Graph traversal, for one. Check Google for more.
Was This Post Helpful? 1
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,262
  • Joined: 27-December 08

Re: Use of Stack Data Structure

Posted 28 December 2009 - 02:06 PM

Commands in programming language. For example, recursive method calls use a stack to store order or precedence for each call. Also, if you've worked in Java, you may have heard of a StackOverflowError.
Was This Post Helpful? 0
  • +
  • -

#7 john0555  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-December 09

Re: Use of Stack Data Structure

Posted 30 December 2009 - 03:40 AM

Thanks for the post. I also need it.
Was This Post Helpful? 0
  • +
  • -

#8 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 609
  • Joined: 01-October 08

Re: Use of Stack Data Structure

Posted 02 January 2010 - 10:19 AM

One of the first uses was for return addresses. My first computer(IBM 1620) did not have the ability to store more than one return address as pointed out by Edsger Dijkstra.

	Function factorial(ByVal n As Integer) As Integer
		If n <= 1 Then
			Return 1
		Else
			Return factorial(n - 1) * n
		End If
	End Function
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		TextBox1.Text = factorial(5).ToString
		test1()
	End Sub
	Private Sub test1()
		test2()
		Debug.WriteLine("1")
	End Sub
	Private Sub test2()
		test3()
		Debug.WriteLine("2")
	End Sub
	Private Sub test3()
		test4()
		Debug.WriteLine("3")
	End Sub
	Dim x As Integer = 0
	Private Sub test4()
		Debug.WriteLine("4")
		x += 1
		If x < 5 Then test4()
	End Sub


Was This Post Helpful? 0
  • +
  • -

#9 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: Use of Stack Data Structure

Posted 03 January 2010 - 01:49 PM

OpenGL saves matrices on a stack, eg. glPushMatrix(), glPopMatrix().

Also I'm not sure if anyone mentioned it but undo/redo functionality can be (and according to my prof) usually is handled by a stack.

This post has been edited by Tom9729: 03 January 2010 - 01:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1