📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 17definition

DATA ABSTRACTION · Part 4

Chapter 9: Front Matter · COMPUTER SCIENCE

rational( x , y ) - - selector numer(x) → returns the numerator of rational number x denom(y) → returns the denominator of rational number y Example: An ADT for rational numbers In the above example, rational () is the constructor numer () and denom () both are selectors. In this case, selectors are declared inside the constructor but not defined. The pseudo code for the representation of the rational number using the above constructor and selector is x,y := , rational( x,y ) numer( x )/denom( y ) - - output : .6666666666666665 Lists,Tuples . To implement the data abstraction, Programming languages like Python provides a compound structure called Pair which is made up of list or Tuple.

The first way to implement pairs is with the List construct. . . List List is constructed by placing expressions within square brackets separated by commas .

Such an expression is called a list literal. List can store multiple values. Each value can be of any type and can even be another list. 12th Computer Chapter - - Data Abstraction Example for List [ , ].

The elements of a list can be accessed in two ways. The first way is via our familiar method of multiple assignment, which unpacks a list into its elements and binds each element to a different name. lst := [ , ] x, y := lst In the above example x will become10 and y will become . A second method for accessing the elements in a list is by the element selection operator.

Unlike a list literal, a square- brackets expression directly following another expression does not evaluate to a list value, but instead selects an element from the value of the preceding expression. lst[ ] lst[ ] In both the example mentioned above mathematically we can represent list similar to a set. lst[( , ), ( , )] - where ( , ) ( , ) Index position value Index position value Any way of bundling two values together into one can be considered as a pair. Lists are a common method to do so.

Therefore List

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →