Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

DATA STRUCTURES USING C++ Chapter 5
CHP-5 LinkedList.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
M180: Data Structures & Algorithms in Java
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Chapter Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
©Brooks/Cole, 2003 Chapter 11 Data Structures. ©Brooks/Cole, 2003 Data Structure Data structure uses collection of related variables that can be accessed.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Summary of lectures (1 to 11)
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
C++ fundamentals.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Data Structures Using C++ 2E
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Lecture No.01 Data Structures Dr. Sohail Aslam
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Chapter 5 – Dynamic Data Structure Par1: Abstract Data Type DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
(1 - 1) Introduction to C Data Structures & Abstract Data Types Instructor - Andrew S. O’Fallon CptS 122 (August 26, 2015) Washington State University.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Kovács Zita 2014/2015. II. félév DATA STRUCTURES AND ALGORITHMS 26 February 2015, Linked list.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
1 Linked Lists Chapter 3. 2 Objectives You will be able to: Describe an abstract data type for lists. Understand and use an implementation of a List ADT.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
  A linked list is a collection of components called nodes  Every node (except the last one) contains the address of the next node  The address of.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
CS212: Data Structures and Algorithms Lecture # 4 Linked List.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
C++ Programming:. Program Design Including
© 2016 Pearson Education, Ltd. All rights reserved.
CSCI-255 LinkedList.
Lectures linked lists Chapter 6 of textbook
Linked Lists Chapter 6 Section 6.4 – 6.6
Data Structure Interview Question and Answers
CS2006- Data Structures I Chapter 5 Linked Lists I.
Data Structure and Algorithms
Linked lists.
CS212D: Data Structures Week 5-6 Linked List.
Introduction to Data Structure
Linked Lists.
Data Structures & Algorithms
Dynamic allocation (continued)
ㅎㅎ Sixth step for Learning C++ Programming Pointer new, delete String
Linked lists.
Dynamic Data Structures
Presentation transcript:

Chapter 1 Object Oriented Programming

OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques may include features such as Data abstraction. Encapsulation. Polymorphism. Inheritance. Many modern programming languages now support OOP.

Abstract data types An outline of the program containing its requirements should precede the coding process for a project. Then, in the later stage, the implementation may start with specific data structure. First, specify each task in terms of inputs and outputs. Be concerned with what the program should do. For example, if an item is needed to accomplish some tasks, the item is specified by the operations performed on it not by its structure. When the implementation starts, it decides which data structure to use to make the execution more efficient. An item specified in terms of operations is called an abstract data type. ADT- An abstract data type can be defined by the operations that are done on the data regardless of its type. ADT- A set of data values and associated operations that are precisely specified independent of any particular implementation. ADT- Mathematical description of an object with set of operations on the object.

Some information before starting You already learned that addresses of variables were assigned to pointers. However, pointers can refer to unknown locations that are accessible only through their addresses not by names. These locations must be set by the memory manager dynamically during the run of the program. To dynamically allocate and de-allocate memory, two functions are used: 1. new – takes from memory as much space as needed to store an object. Ex : p = new int; 2. delete – return the space that is accessible from p and is no longer needed. Ex : delete p; Note : an address has to be assigned to a pointer, if it can’t be the address of any location, it should be a null address, which is simply 0.

Chapter 3 Linked Lists

Linked list An array is a very useful data structure in programming languages. However, it has at least two limitations that can be overcome by using linked structure. It is a collection of nodes storing data and links (using addresses) to other nodes. A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next record in the sequence. The most flexible linked structure’s implementation is by using pointers. Linked lists are among the simplest and most common data structures; they provide an easy implementation for several important abstract data structures, including stacks, queues and arrays.

3.1 Singly Linked Lists Linked list – a data structure that composed of nodes, each node holding some information and a pointer to another node in the list. Singly linked list – a node has a link only to its successor in the sequence of nodes in the list. Note : Only one variable is used to access any node in the list. The last node on the list can be recognized by the null pointer.

Example : class IntSLLNode { public: IntSLLNode() { next = 0; } IntSLLNode(int i, IntSLLNode *ptr = 0) { info = i; next = ptr; } int info; IntSLLNode *next; };

Now, how to create the linked list 1. Create a new node by executing the declaration and assignment : IntSLLNode *p = new IntSLLNode(10); This statement create a node on the list and make p points to it. The constructor assigns the number 10 to the info member of this node. The constructor assigns null to its next member. 2. Then any new node is included in the list by making the next member of the first node a pointer to the new node. 3. The second node is created by : p -> next = new IntSLLNode (8);

Problem : The longer the linked list, the longer the chain of next s to access the nodes at the end of the list when using pointers. 1. If you missed a node in the chain, then a wrong assignment is made 2. The flexibility of using linked lists is diminished. So, other ways of accessing nodes are needed. One of them is : To keep two pointers: one to the first node(Head), and one to the last(Tail).

3.1.1 Insertion 1. inserting a new node at the beginning of a singly linked list

3.1.1 Insertion (cont’) 2. inserting a new node at the end of a singly linked list

Insert At the beginningInsert at the end addToTail(int el) { if (tail != 0) { // if list not empty; tail->next = new IntSLLNode(el); tail = tail->next; } else head = tail = new IntSLLNode(el); } addToHead(int el) { head = new IntSLLNode(el,head); if (tail == 0) tail = head; }