From the course: Programming Foundations: Discrete Mathematics

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Create datatypes that use lists

Create datatypes that use lists

From the course: Programming Foundations: Discrete Mathematics

Start my 1-month free trial

Create datatypes that use lists

- [Voiceover] At this point, we've seen how to create our own datatypes of lists, for example, primes. We've also seen how to perform functions on lists. This time I want to show you how you can create a datatype that contains both primitive data and a list. In this example, we're going to model the process of making a salad. When making a salad you first choose what type of lettuce you want. Next, you put on a dressing and then you might have one or more toppings. So we will have lettuce, dressing, and a list of toppings. Let's get started. First, I'm going to create a datatype called lettuce. And the possible values for lettuce are going to be Romaine, IceBerg, SpringMix, and Spinach. Next, I need a datatype to represent the dressing for the salad. The dressings might be Italian, Caesar, Ranch, French, or BleuCheese. Now I need a datatype for my toppings. The toppings might include, Olives, Tomatoes, Parmesan, Cucumbers, Onions, and for now let's just add Croutons. There's lot more…

Contents