skip to main | skip to sidebar

advance datastrucuters

Thursday, April 15, 2010

5.1.1. Using Lists as Stacks¶



The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an item to the top of the stack, use append(). To retrieve an item from the top of the stack, use pop() without an explicit index. For example:

>>> stack = [3, 4, 5]
>>> stack.append(6)
>>> stack.append(7)
>>> stack
[3, 4, 5, 6, 7]
>>> stack.pop()
7
>>> stack
[3, 4, 5, 6]
>>> stack.pop()
6
>>> stack.pop()
5
>>> stack
[3, 4]

Posted by OPERATING SYSTEMS at 6:11 PM

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

anlytics

COUNTER

counter

HTML hit counter - Quick-counter.net

Feedjit

GOOGLE ANALYTICS

GOOGLE ANALYTICS

ADSENSE POLICY

This post confirms my ownership of the site and that this site adheres to Google AdSense program policies and Terms and Conditions

UR VISTING NO:

Website counter

Google Search Engine

About Me

OPERATING SYSTEMS
View my complete profile

Blog Archive

  • ►  2011 (88)
    • ►  October (38)
    • ►  February (49)
    • ►  January (1)
  • ▼  2010 (29)
    • ►  August (19)
    • ▼  April (10)
      • 5.1.1. Using Lists as Stacks¶
      • video resuts of searching in data structres
      • video resuts of data structures
      • The IEEE Standard for Floating-Point Arithmetic (I...
      • The IEEE Standard for Floating-Point Arithmetic (I...
      • Double precision floating-point format
      • String (computer science)
      • In computer science, the term integer is used to r...
      • Character (computing)
      • Boolean data type
  • ►  2009 (9)
    • ►  December (9)

counter

HTML hit counter - Quick-counter.net

LOCATION WIDGET

Locations of visitors to this page