E create a class employee whose private members are

This preview shows page 38 - 41 out of 84 pages.

e) Create a class employee whose private members are int age, float salary and float weight while the public members are employee () which is a constructor to initialize employee age, ~employee() a destructure which will destroy employee object(de-allocate memory), getinfo() to get employee information and display() to display employee information. The member functions must be defined outside the class. f) Discuss the differences between:
BBIT 106: DATA STRUCTURES AND ALGORITHMS 37 ii. Class and union iii. Destructor and constructor 6.10. Summary In this lesson, we have learnt that a class is a template used to create objects. An object is an instance of a class. The objects bind together data and methods that will act on the data. Examples of classes can be tree, linked list, queue, stack e.t.c. The members of a class can be classified into data members and member functions. The member functions can be defined inside class declaration or outside. Constructor and destructor are two important member functions used to initialize an object and delete an object from memory respectively. 6.11. Suggested reading [1]. Data structures using C and C++, 2nd Edition by Yedidyah Langsam, Aaron J.Augenstein and Aaron M.Tenebaum: Pubslisher: Pearson. [2]. Data structures and algorithms in c++ by Michael T.Goodrich,Robertio Tamassia and David Mount: Publisher: Wiley [3]. Fundamentals of data structures in c++ by Ellis Horowitz,Sartaj Sahni and Dinesh Mehta. a. Publisher:Galgotia [4]. Introduction to data structures and algorithms with c++ by Glenn W.Rowe . Publisher: Prentice Hall. Lesson 7: Linked lists 7.1. Introduction A linked list is a linear data structure which consists of collection of nodes. Each node in the list has two components: i. Data field- To store the values ii. Link field-To store address to the next node Header (first): Contains address to the first node. The last node points to null. 7.2. Lesson objectives By the end of this lesson, the students should be able to: Explain applications of a linked list Discuss operations that can be applied on linked lists Create and use linked lists using pointers 7.3. Lesson outline This lesson is organized as follows: 7.1. Introduction Header NULL
BBIT 106: DATA STRUCTURES AND ALGORITHMS 38 7.2. Lesson objectives 7.3. Lesson outline 7.4. Declaration of linked lists 7.5. Basic operations of a linked list 7.6. Applications of linked lists 7.7. Types of linked lists 7.8. Building a linked list 7.9. Revision questions 7.10. Summary 7.11. Suggested reading 7.4. Declaration of linked lists Singly linked list: A linked list can be declared as follows: struct node { int data; node *next; }; Doubly linked list: A doubly linked list is declared as follows: struct doublenode { int data ; doublenode *next; double node *previous; }; 7.5. Basic Operations of a Linked List Search: Operation used to search a list to determine whether a particular item is in the list.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture