Chapter 2

Sets and Linked Lists

IN THIS CHAPTER

Bullet Working with sets

Bullet Creating and modifying a linked list

Bullet Identifying problems with sets and linked lists

An array can be handy for storing data that consists of the same type of information, such as integers. However, arrays can often be too restrictive. You must define the size of an array ahead of time, and you can only store one data type. In addition, searching, rearranging, or deleting data from an array can be cumbersome.

To solve the problems of arrays, programming languages have come up with a variety of solutions. The obvious solution involves modifying the way arrays work, such as letting you create dynamic (resizable) arrays that can store a special Variant data type. Unlike an Integer data type (which can hold only whole numbers) or a String data type (which can hold only text), a Variant data type can hold both numbers and text. (Not all programming languages offer dynamic arrays or Variant data types.)

Instead of modifying the way arrays work, many programming languages allow you to create other types of data structures. Two popular alternatives to arrays are sets and lists. This chapter shows you how to use sets and lists ...

Get Beginning Programming All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.