100% found this document useful (6 votes)
40 views

Data Structure Algorithms Using C A Practical Implementation 1st edition by Sachi Nandan Mohanty, Pabitra Kumar Tripathy 9781119752035 1119752035 - The ebook in PDF format is ready for download

The document provides information on various eBooks related to data structures and algorithms, including titles and links for downloading. It features books such as 'Data Structure Algorithms Using C' and 'Mastering Machine Learning with Python.' Additionally, it includes details about the authors, publishers, and a comprehensive table of contents for a specific book.

Uploaded by

djonzomureta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
40 views

Data Structure Algorithms Using C A Practical Implementation 1st edition by Sachi Nandan Mohanty, Pabitra Kumar Tripathy 9781119752035 1119752035 - The ebook in PDF format is ready for download

The document provides information on various eBooks related to data structures and algorithms, including titles and links for downloading. It features books such as 'Data Structure Algorithms Using C' and 'Mastering Machine Learning with Python.' Additionally, it includes details about the authors, publishers, and a comprehensive table of contents for a specific book.

Uploaded by

djonzomureta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Visit ebookball.

com to download the full version and


explore more ebook or textbook

Data Structure Algorithms Using C A Practical


Implementation 1st edition by Sachi Nandan
Mohanty, Pabitra Kumar Tripathy 9781119752035
1119752035
_____ Click the link below to download _____
https://ebookball.com/product/data-structure-algorithms-
using-c-a-practical-implementation-1st-edition-by-sachi-
nandan-mohanty-pabitra-kumar-
tripathy-9781119752035-1119752035-18754/

Explore and download more ebook or textbook at ebookball.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Data Structures Using C A Practical Approach for Beginners


1st edition by Amol Jagtap, Ajit Mali 9781000470741
1000470741
https://ebookball.com/product/data-structures-using-c-a-practical-
approach-for-beginners-1st-edition-by-amol-jagtap-ajit-
mali-9781000470741-1000470741-18746/

Problem Solving in Data Structures and Algorithms Using C


1st Edition by Hemant Jain ISBN 9352655915 9789352655915

https://ebookball.com/product/problem-solving-in-data-structures-and-
algorithms-using-c-1st-edition-by-hemant-jain-
isbn-9352655915-9789352655915-15768/

Problem Solving in Data Structures and Algorithms Using C


1st Edition by Hemant Jain ISBN 1540407306 9781540407306

https://ebookball.com/product/problem-solving-in-data-structures-and-
algorithms-using-c-1st-edition-by-hemant-jain-
isbn-1540407306-9781540407306-15866/

Mastering Machine Learning with Python in Six Steps A


Practical Implementation Guide to Predictive Data
Analytics Using Python 1st Edition by Manohar Swamynathan
ISBN 1484228669 9781484228661
https://ebookball.com/product/mastering-machine-learning-with-python-
in-six-steps-a-practical-implementation-guide-to-predictive-data-
analytics-using-python-1st-edition-by-manohar-swamynathan-
isbn-1484228669-9781484228661-16112/
Mastering Machine Learning with Python in Six Steps A
Practical Implementation Guide to Predictive Data
Analytics Using Python 1st Edition by Manohar Swamynathan
ISBN 1484228669 9781484228661
https://ebookball.com/product/mastering-machine-learning-with-python-
in-six-steps-a-practical-implementation-guide-to-predictive-data-
analytics-using-python-1st-edition-by-manohar-swamynathan-
isbn-1484228669-9781484228661-16088/

Data Structures and Algorithms Made Easy Data Structure


and Algorithmic Puzzles 5th Edition by Careermonk
Publications, Narasimha Karumanchi ISBN 9788193245279
https://ebookball.com/product/data-structures-and-algorithms-made-
easy-data-structure-and-algorithmic-puzzles-5th-edition-by-careermonk-
publications-narasimha-karumanchi-isbn-9788193245279-15800/

Windows Programming Development Memory Management


Algorithms And Implementation In C 1st edition by Bill
Blunden 1556223471 978-1556223471
https://ebookball.com/product/windows-programming-development-memory-
management-algorithms-and-implementation-in-c-1st-edition-by-bill-
blunden-1556223471-978-1556223471-15236/

Data Structures and Algorithms in C 1st edition by Adam


Drozdek ASIN B002WLXMBY

https://ebookball.com/product/data-structures-and-algorithms-in-c-1st-
edition-by-adam-drozdek-asin-b002wlxmby-25076/

Principles of Data Structures Using C and C 1st Edition by


Vinu Das ISBN 8122418589 9788122418583

https://ebookball.com/product/principles-of-data-structures-using-c-
and-c-1st-edition-by-vinu-das-isbn-8122418589-9788122418583-15766/
Data Structure and Algorithms
Using C++
Scrivener Publishing
100 Cummings Center, Suite 541J
Beverly, MA 01915-6106

Publishers at Scrivener
Martin Scrivener ([email protected])
Phillip Carmical ([email protected])
Data Structure
and Algorithms Using C++

A Practical Implementation

Edited by
Sachi Nandan Mohanty
ICFAI Foundation For Higher Education, Hyderabad, India
and
Pabitra Kumar Tripathy
Kalam Institute of Technology, Berhampur, India
This edition first published 2021 by John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, USA
and Scrivener Publishing LLC, 100 Cummings Center, Suite 541J, Beverly, MA 01915, USA
© 2021 Scrivener Publishing LLC
For more information about Scrivener publications please visit www.scrivenerpublishing.com.

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or
transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or other-
wise, except as permitted by law. Advice on how to obtain permission to reuse material from this title
is available at http://www.wiley.com/go/permissions.

Wiley Global Headquarters


111 River Street, Hoboken, NJ 07030, USA

For details of our global editorial offices, customer services, and more information about Wiley prod-
ucts visit us at www.wiley.com.

Limit of Liability/Disclaimer of Warranty


While the publisher and authors have used their best efforts in preparing this work, they make no rep­
resentations or warranties with respect to the accuracy or completeness of the contents of this work and
specifically disclaim all warranties, including without limitation any implied warranties of merchant-­
ability or fitness for a particular purpose. No warranty may be created or extended by sales representa­
tives, written sales materials, or promotional statements for this work. The fact that an organization,
website, or product is referred to in this work as a citation and/or potential source of further informa­
tion does not mean that the publisher and authors endorse the information or services the organiza­
tion, website, or product may provide or recommendations it may make. This work is sold with the
understanding that the publisher is not engaged in rendering professional services. The advice and
strategies contained herein may not be suitable for your situation. You should consult with a specialist
where appropriate. Neither the publisher nor authors shall be liable for any loss of profit or any other
commercial damages, including but not limited to special, incidental, consequential, or other damages.
Further, readers should be aware that websites listed in this work may have changed or disappeared
between when this work was written and when it is read.

Library of Congress Cataloging-in-Publication Data

ISBN 978-1-119-75054-3

Cover image: Pixabay.Com


Cover design by Russell Richardson

Set in size of 11pt and Minion Pro by Manila Typesetting Company, Makati, Philippines

Printed in the USA

10 9 8 7 6 5 4 3 2 1
Contents

Preface xi
1 Introduction to Data Structure 1
1.1 Definition and Use of Data Structure 1
1.2 Types of Data Structure 2
1.3 Algorithm 3
1.4 Complexity of an Algorithm 6
1.5 Efficiency of an Algorithm 7
1.6 Asymptotic Notations 8
1.7 How to Determine Complexities 9
1.8 Questions 13
2 Review of Concepts of ‘C++’ 15
2.1 Array 15
2.1.1 One-Dimensional Array 16
2.1.2 Multi-Dimensional Array 17
2.1.3 String Handling 20
2.2 Function 26
2.2.1 User Defined Functions 26
2.2.2 Construction of a Function 27
2.2.3 Actual Argument and Formal Argument 31
2.2.4 Call by Value and Call by Reference 32
2.2.5 Default Values for Parameters 34
2.2.6 Storage Class Specifiers 35
2.3 Pointer 37
2.3.1 Declaration of a Pointer 37
2.3.2 Initialization of a Pointer 37
2.3.3 Arithmetic With Pointer 38
2.3.4 Passing of a Pointer to Function 39
2.3.5 Returning of a Pointer by Function 40
2.3.6 C++ Null Pointer 41

v
vi Contents

2.4 Structure 42
2.4.1 The typedef Keyword 46
2.5 Questions 47
3 Sparse Matrix 49
3.1 What is Sparse Matrix 49
3.2 Sparse Matrix Representations 49
3.3 Algorithm to Represent the Sparse Matrix 51
3.4 Programs Related to Sparse Matrix 52
3.5 Why to Use Sparse Matrix Instead of Simple Matrix? 56
3.6 Drawbacks of Sparse Matrix 57
3.7 Sparse Matrix and Machine Learning 57
3.8 Questions 58
4 Concepts of Class 59
4.1 Introduction to CLASS 59
4.2 Access Specifiers in C++ 60
4.3 Declaration of Class 60
4.4 Some Manipulator Used In C++ 62
4.5 Defining the Member Functions Outside of the Class 64
4.6 Array of Objects 64
4.7 Pointer to Object 66
4.8 Inline Member Function 67
4.9 Friend Function 69
4.9.1 Simple Friend Function 69
4.9.2 Friend With Inline Substitution 70
4.9.3 Granting Friendship to Another Class
(Friend Class) 71
4.9.4 More Than One Class Having the Same
Friend Function 73
4.10 Static Data Member and Member Functions 75
4.11 Constructor and Destructor 78
4.11.1 Constructor 78
4.11.1.1 Empty Constructor 79
4.11.1.2 Default Constructor 79
4.11.1.3 Parameterized Constructors 80
4.11.1.4 Copy Constructor 81
4.11.2 Destructor 83
4.12 Dynamic Memory Allocation 84
4.13 This Pointer 86
4.14 Class Within Class 87
4.15 Questions 89
Contents vii

5 Stack 91
5.1 STACK 91
5.2 Operations Performed With STACK 91
5.3 ALGORITHMS 93
5.4 Applications of STACK 96
5.5 Programming Implementations of STACK 106
5.6 Questions 126
6 Queue 129
6.1 Queue 129
6.2 Types of Queue 129
6.3 Linear Queue 129
6.4 Circular Queue 134
6.5 Double Ended Queue 138
6.6 Priority Queue 139
6.7 Programs 142
6.8 Questions 165
7 Linked List 167
7.1 Why Use Linked List? 167
7.2 Types of Link List 167
7.3 Single Link List 168
7.4 Programs Related to Single Linked List 177
7.4.1 /* Creation of a Linked List */ 177
7.4.2 /* Insert a Node Into a Simple Linked List at
the Beginning */ 178
7.4.3 /* Insert a Node Into a Simple Linked List at
the End of the List */ 180
7.4.4 /* Insert a Node Into a Simple Linked List
When the Node Is Known */ 182
7.4.5 /* Insert a Node Into a Simple Linked List
Information Is Known and Put After Some
Specified Node */ 184
7.4.6 /* Deleting the First Node From a Simple
Linked List */ 187
7.4.7 /* Deleting the Last Node From a Simple
Linked List */ 189
7.4.8 /* Deleting a Node From a Simple Linked
List When Node Number Is Known */ 191
7.4.9 Deleting a Node From a Simple Linked List
When Information of a Node Is Given 193
viii Contents

7.4.10 /* SEARCH A NODE INTO A SIMPLE LINKED


LIST WITH INFORMATION IS KNOWN*/ 197
7.4.11 /* Sorting a Linked List in Ascending Order */ 199
7.4.12 /* Reversing a Linked List */ 202
7.4.13 Program for Student Data Using Linked List 203
7.5 Double Link List 210
7.6 Programs on Double Linked List 216
7.6.1 /* Creation of Double Linked List */ 216
7.6.2 /* Inserting First Node in the Doubly
Linked List */ 218
7.6.3 /*Inserting a Node in the Doubly Linked List
When Node Number Is Known*/ 220
7.6.4 /*Inserting a Node in the Doubly Linked List
When Information Is Known*/ 223
7.6.5 /* Delete First Node From a Double Linked List */ 226
7.6.6 /*Delete the Last Node From the Double
Linked List*/ 229
7.7 Header Linked List 231
7.7.1 /* Inserting a Node Into a Header Linked List */ 233
7.8 Circular Linked List 235
7.9 Application of Linked List 239
7.9.1 Addition of Two Polynomial 239
7.9.2 /* Polynomial With Help of Linked List */ 240
7.9.3 Program for Linked Queue 241
7.9.4 Program for Linked Stack 243
7.10 Garbage Collection and Compaction 245
7.11 Questions 247
8 TREE 249
8.1 Tree Terminologies 249
8.2 Binary Tree 251
8.3 Representation of Binary Tree 253
8.3.1 Array Representation of a Tree 253
8.3.2 Linked List Representation of a Tree 254
8.4 Operations Performed With the Binary Tree 254
8.4.1 /*Creation of a Tree*/ 255
8.5 Traversing With Tree 256
8.5.1 /* Binary Tree Traversal */ 259
8.6 Conversion of a Tree From Inorder and Preorder 262
Contents ix

8.7 Types of Binary Tree 265


8.8 Expression Tree 265
8.9 Binary Search Tree 268
8.10 Height Balanced Tree (AVL Tree) 272
8.11 Threaded Binary Tree 277
8.12 Heap Tree 279
8.13 Huffman Tree 282
8.14 Decision Tree 286
8.15 B-Tree 287
8.16 B + Tree 292
8.17 General Tree 293
8.18 Red–Black Tree 293
8.19 Questions 294
9 Graph 295
9.1 Graph Terminologies 295
9.2 Representation of Graph 301
9.3 Traversal of Graph 305
9.3.1 Breadth First Search (BFS) 305
9.3.2 Depth First Search 311
9.4 Spanning Tree 315
9.4.1 Kruskal Algorithm 315
9.4.2 Prim’s Algorithm 318
9.5 Single Source Shortest Path 322
9.5.1 Bellman–Ford Algorithm 323
9.5.2 Dijkstra’s Algorithm 327
9.6 All Pair Shortest Path 335
9.7 Topological Sorting 345
9.8 Questions 347
10 Searching and Sorting 349
10.1 Linear Search 349
10.2 Binary Search 351
10.3 Bubble Sort 355
10.4 Selection Sort 359
10.5 Insertion Sort 361
10.6 Merge Sort 363
10.7 Quick Sort 366
10.8 Radix Sort 369
10.9 Heap Sort 372
10.10 Questions 389
x Contents

11 Hashing 391
11.1 Hash Functions 391
11.2 Collisions 393
11.3 Collision Resolution Methods 393
11.4 Clustering 394
11.5 Questions 395
Index 397
Preface

Welcome to the first edition of Data Structures and Algorithms Using C++.
A data structure is the logical or mathematical arrangement of data in
memory. To be effective, data has to be organized in a manner that adds to
the efficiency of an algorithm and also describe the relationships between
these data items and the operations that can be performed on these items.
The choice of appropriate data structures and algorithms forms the funda-
mental step in the design of an efficient program. Thus, a deep understand-
ing of data structure concepts is essential for students who wish to work
on the design and implementation of system software written in C++, an
object-oriented programming language that has gained popularity in both
academia and industry. Therefore, this book was developed to provide
comprehensive and logical coverage of data structures like stacks, queues,
linked lists, trees and graphs, which makes it an excellent choice for learn-
ing data structures. The objective of the book is to introduce the concepts
of data structures and apply these concepts in real-life problem solving.
Most of the examples presented resulted from student interaction in the
classroom. This book utilizes a systematic approach wherein the design of
each of the data structures is followed by algorithms of different operations
that can be performed on them and the analysis of these algorithms in
terms of their running times.
This book was designed to serve as a textbook for undergraduate engi-
neering students across all disciplines and postgraduate level courses in
computer applications. Young researchers working on efficient data storage
and related applications will also find it to be a helpful reference source to
guide them in the newly established techniques of this rapidly growing
research field.

Dr. Sachi Nandan Mohanty and


Prof. Pabitra Kumar Tripathy
December 2020

xi
1
Introduction to Data Structure

1.1 Definition and Use of Data Structure


Data structure is the representation of the logical relationship existing
between individual elements of data. In other words the data structure is a
way of organizing all data items that considers not only the elements stored
but also their relationship to each other.
Data structure specifies

• Organization of data
• Accessing methods
• Degree of associativity
• Processing alternatives for information

The data structures are the building blocks of a program and hence the
selection of a particular data structure stresses on

• The data structures must be rich enough in structure to


reflect the relationship existing between the data, and
• The structure should be simple so that we can process data
effectively whenever required.

In mathematically Algorithm + Data Structure = Program


Finally we can also define the data structure as the “Logical and mathe-
matical model of a particular organization of data”

Sachi Nandan Mohanty and Pabitra Kumar Tripathy. Data Structure and Algorithms Using C++:
A Practical Implementation, (1–14) © 2021 Scrivener Publishing LLC

1
2 Data Structure and Algorithms Using C++

1.2 Types of Data Structure


Data structure can be broadly classified into two categories as Linear and
Non-Linear

DATA STRUCTURE

LINEAR NON LINEAR

ARRAY QUEUE STACK TREE GRAPH TABLES SETS

Linear Data Structures


In linear data structures, values are arranged in linear fashion. Arrays,
linked lists, stacks, and queues are the examples of linear data structures in
which values are stored in a sequence.

Non-Linear Data Structure


This type is opposite to linear. The data values in this structure are not
arranged in order. Tree, graph, table, and sets are the examples of non-
linear data structure.

Operations Performed in Data Structure


In data structure we can perform the operations like

• Traversing
• Insertion
• Deletion
• Merging
• Sorting
• Searching
Introduction to Data Structure 3

1.3 Algorithm
The step by step procedure to solve a problem is known as the ALGORITHM.
An algorithm is a well-organized, pre-arranged, and defined computational
module that receives some values or set of values as input and provides a
single or set of values as out put. These well-defined computational steps
are arranged in sequence, which processes the given input into output.
An algorithm is said to be accurate and truthful only when it provides
the exact wanted output.
The efficiency of an algorithm depends on the time and space complex-
ities. The complexity of an algorithm is the function which gives the run-
ning time and/or space in terms of the input size.

Steps Required to Develop an Algorithm


• Finding a method for solving a problem. Every step of an
algorithm should be defined in a precise and in a clear man-
ner. Pseudo code is also used to describe an algorithm.
• The next step is to validate the algorithm. This step includes
all the steps in our algorithm and should be done manually
by giving the required input, perform the required steps
including in our algorithm and should get the required
amount of output in a finite amount of time.
• Finally implement the algorithm in terms of programming
language.

Mathematical Notations and Functions


™™ Floor and Ceiling Functions
Floor function returns the greatest integer that does not exceed
the number.
Ceiling function returns the least integer that is not less than
the number.

no denotes the floor function

no denotes the ceil function

Ex :
5.23 = 5 5.23 =6
4 Data Structure and Algorithms Using C++

™™ Remainder Function
To find the remainder “mod” function is being used as

A mod B

™™ To find the Integer and Absolute value of a number


INT(5.34) = 5 This statement returns the integer part of
the number
INT(- 6.45) = 6 This statement returns the absolute as well
as the integer portion of the number

™™ Summation Symbol
To add a series of number as a1+ a2 + a3 +…………+ an the
symbol Σ is used

n
Σ ai
i=1

™™ Factorial of a Number
The product of the positive integers from 1 to n is known as
the factorial of n and it is denoted as n!.

0! = 1

Algorithemic Notations
While writing the algorithm the comments are provided with in [ ].
The assignment should use the symbol “: =” instead of “=”
For Input use Read : variable name
For output use write : message/variable name

The control structures can also be allowed to use inside an algorithm but
their way of approaching will be some what different as
Simple If
If condition, then:
Statements
[end of if structure]
Introduction to Data Structure 5

If…else
If condition, then:
Statements
Else :
Statements
[end of if structure]

If…else ladder
If condition1, then:
Statements
Else If condition2, then:
Statements
Else If condition3, then:
Statements
…………………………………………

…………………………………………

…………………………………………
Else If conditionN, then:
Statements
Else:
Statements
[end of if structure]

LOOPING CONSTRUCT
Repeat for var = start_value to end_value by
step_value
Statements
[end of loop]

Repeat while condition:


Statements
[end of loop]
Ex : repeat for I = 1 to 10 by 2
Write: i
[end of loop]

OUTPUT
1 3 5 7 9
6 Data Structure and Algorithms Using C++

1.4 Complexity of an Algorithm


The complexity of programs can be judged by criteria such as whether
it satisfies the original specification task, whether the code is readable.
These factors affect the computing time and storage requirement of the
program.

Space Complexity
The space complexity of a program is the amount of memory it needs to
run to completion. The space needed by a program is the sum of the fol-
lowing components:

• A fixed part that includes space for the code, space for sim-
ple variables and fixed size component variables, space for
constants, etc.
• A variable part that consists of the space needed by com-
ponent variables whose size is dependent on the particular
problem instance being solved, and the stack space used by
recursive procedures.

Time Complexity
The time complexity of a program is the amount of computer time it needs
to run to completion. The time complexity is of two types such as

• Compilation time
• Runtime

The amount of time taken by the compiler to compile an algorithm is


known as compilation time. During compilation time it does not calculate
for the executable statements, it calculates only the declaration statements
and checks for any syntax and semantic errors.
The run time depends on the size of an algorithm. If the number of
instructions in an algorithm is large, then the run time is also large, and if
the number of instructions in an algorithm is small, then the time for exe-
cuting the program is also small. The runtime is calculated for executable
statements and not for declaration statements.
Introduction to Data Structure 7

Suppose space is fixed for one algorithm then only run time will be con-
sidered for obtaining the complexity of algorithm, these are

• Best case
• Worst case
• Average case

Best Case
Generally, most of the algorithms behave sometimes in best case. In this
case, algorithm searches the element for the first time by itself.
For example: In linear search, if it finds the element for the first time by
itself, then it behaves as the best case. Best case takes shortest time to exe-
cute, as it causes the algorithms to do the least amount of work.

Worst Case
In worst case, we find the element at the end or when searching of elements
fails. This could involve comparing the key to each list value for a total of
N comparisons.
For example in linear search suppose the element for which algorithm
is searching is the last element of array or it is not available in array then
algorithm behaves as worst case.

Average Case
Analyzing the average case behavior algorithm is a little bit complex than
the best case and worst case. Here, we take the probability with a list of
data. Average case of algorithm should be the average number of steps but
since data can be at any place, so finding exact behavior of algorithm is
difficult. As the volume of data increases, the average case of algorithm
behaves like the worst case of algorithm.

1.5 Efficiency of an Algorithm


Efficiency of an algorithm can be determined by measuring the time, space,
and amount of resources it uses for executing the program. The amount of
time taken by an algorithm can be calculated by finding the number of
steps the algorithm executes, while the space refers to the number of units
it requires for memory storage.
8 Data Structure and Algorithms Using C++

1.6 Asymptotic Notations


The asymptotic notations are the symbols which are used to solve the dif-
ferent algorithms and the notations are

• Big Oh Notation (O)


• Little Oh Notation (o)
• Omega Notation (W)
• Theta Notation (q)

Big Oh (O) Notation


This Notation gives the upper bound for a function to within a constant
factor. We write f(n) = O(g(n)) if there are +ve constants n0 and C such
that to the right of n0, the value of f(n) always lies on or below Cg(n)

Omega Notation (W)


This notation gives a lower bound for a function to with in a constant fac-
tor. We write f(n) = Ωg(n) if there are positive constants n0 and C such that
to the right of n0 the value of f(n) always lies on or above Cg(n)

Theta Notation (q)


This notation bounds the function to within constant factors. We say f(n) =
θg(n) if there exists +ve constants n0, C1 and C2 such that to the right of n0
the value of f(n) always lies between c1g(n) and c2(g(n)) inclusive.

Little Oh Notation (o)


F(n) = o(g(n)) iff f(n) = O(g(n)) and f(n) != Ωg(n).

Introduction
An important question is: How efficient is an algorithm or piece of code?
Efficiency covers lots of resources, including:
CPU (time) usage
Memory usage
Disk usage
Network usage
Introduction to Data Structure 9

All are important but we will mostly talk about CPU time
Be careful to differentiate between:

Performance: how much time/memory/disk/... is actually used


when a program is running. This depends on the machine, compiler, etc.,
as well as the code.

Complexity: how do the resource requirements of a program or algorithm


scale, i.e., what happens as the size of the problem being solved gets larger.
Complexity affects performance but not the other way around. The time
required by a method is proportional to the number of “basic operations”
that it performs. Here are some examples of basic operations:
one arithmetic operation (e.g., +, *).
one assignment
one test (e.g., x == 0)
one read
one write (of a primitive type)

Note: As an example,
O(1) refers to constant time.
O(n) indicates linear time;
O(nk) (k fixed) refers to polynomial time;
O(log n) is called logarithmic time;
O(2n) refers to exponential time, etc.
n² + 3n + 4 is O(n²), since n² + 3n + 4 < 2n² for all n > 10. Strictly speaking,
3n + 4 is O(n²), too, but big-O notation is often misused to mean equal to
rather than less than.

1.7 How to Determine Complexities


In general, how can you determine the running time of a piece of code?
The answer is that it depends on what kinds of statements are used.

1. Sequence of statements
statement 1;
statement 2;
...
statement k;
10 Data Structure and Algorithms Using C++

Note: this is code that really is exactly k statements; this is not


an unrolled loop like the N calls to addBefore shown above.)
The total time is found by adding the times for all statements:

total time = time(statement 1) + time


(statement 2) + ... + time(statement k)

If each statement is “simple” (only involves basic opera-


tions) then the time for each statement is constant and the
total time is also constant: O(1). In the following examples,
assume the statements are simple unless noted otherwise.
2. if-then-else statements
if (cond) {
sequence of statements 1
}
else {
sequence of statements 2
}

Here, either sequence 1 will execute, or sequence 2 will execute.


Therefore, the worst-case time is the slowest of the two possi-
bilities: max(time(sequence 1), time(sequence 2)). For exam-
ple, if sequence 1 is O(N) and sequence 2 is O(1) the worst-case
time for the whole if-then-else statement would be O(N).
3. for loops
for (i = 0; i < N; i++) {
sequence of statements
}

The loop executes N times, so the sequence of statements also


executes N times. Since we assume the statements are O(1), the
total time for the for loop is N * O(1), which is O(N) overall.
4. Nested loops
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
sequence of statements
}
}

The outer loop executes N times. Every time the outer loop
executes, the inner loop executes M times. As a result, the
statements in the inner loop execute a total of N * M times.
Thus, the complexity is O(N * M). In a common special case
Introduction to Data Structure 11

where the stopping condition of the inner loop is j < N


instead of j < M (i.e., the inner loop also executes N times),
the total complexity for the two loops is O(N2).
5. Statements with method calls:
When a statement involves a method call, the complexity of
the statement includes the complexity of the method call.
Assume that you know that method f takes constant time,
and that method g takes time proportional to (linear in) the
value of its parameter k. Then the statements below have the
time complexities indicated.
f(k); // O(1)
g(k); // O(k)

When a loop is involved, the same rule applies. For example:


for (j = 0; j < N; j++) g(N);

has complexity (N2). The loop executes N times and each


method call g(N) is complexity O(N).

Examples
Q1. What is the worst-case complexity of the each of the following code
fragments?

Two loops in a row:


for (i = 0; i < N; i++) {
sequence of statements
}
for (j = 0; j < M; j++) {
sequence of statements
}

Answer: Th
 e first loop is O(N) and the second loop is O(M). Since you
do not know which is bigger, you say this is O(N+M). This can
also be written as O(max(N,M)). In the case where the second
loop goes to N instead of M the complexity is O(N). You can
see this from either expression above. O(N+M) becomes O(2N)
and when you drop the constant it is O(N). O(max(N,M))
becomes O(max(N,N)) which is O(N).
12 Data Structure and Algorithms Using C++

Q2. How would the complexity change if the second loop went to N
instead of M?
A nested loop followed by a non-nested loop:
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
sequence of statements
}
}
for (k = 0; k < N; k++) {
sequence of statements
}

Answer: Th
 e first set of nested loops is O(N2) and the second loop is
O(N). This is O(max(N2,N)) which is O(N2).
Q3. A nested loop in which the number of times the inner loop executes
depends on the value of the outer loop index:
for (i = 0; i < N; i++) {
for (j = i; j < N; j++) {
sequence of statements
}
}

Answer: W
 hen i is 0 the inner loop executes N times. When i is 1 the
inner loop executes N-1 times. In the last iteration of the outer
loop when i is N-1 the inner loop executes 1 time. The number
of times the inner loop statements execute is N + N-1 + ... + 2 +
1. This sum is N(N+1)/2 and gives O(N2).
Q4. For each of the following loops with a method call, determine the
overall complexity. As above, assume that method f takes constant time,
and that method g takes time linear in the value of its parameter.

a. for (j = 0; j < N; j++) f(j);


b. for (j = 0; j < N; j++) g(j);
c. for (j = 0; j < N; j++) g(k);

Answer: a. E
 ach call to f(j) is O(1). The loop executes N times so it is N x
O(1) or O(N).
b. The first time the loop executes j is 0 and g(0) takes “no oper-
ations.” The next time j is 1 and g(1) takes 1 operations. The
last time the loop executes j is N-1 and g(N-1) takes N-1 oper-
ations. The total work is the sum of the first N-1 numbers and
is O(N2).
Introduction to Data Structure 13

c. Each time through the loop g(k) takes k operations and the
loop executes N times. Since you do not know the relative size
of k and N, the overall complexity is O(N x k).

1.8 Questions
1. What is data structure?
2. What are the types of operations that can be performed with
data structure?
3. What is asymptotic notation and why is this used?
4. What is complexity and its type?
5. Find the complexity of 3n2 + 5n.
6. Distinguish between linear and non-linear data structure.
7. Is it necessary is use data structure in every field? Justify
your answer.
2
Review of Concepts of ‘C++’

2.1 Array
Whenever we want to store some values then we have to take the help of a
variable, and for this we must have to declare it before its use. If we want
to store the details of a student so for this purpose we have to declare the
variables as
char name [20], add[30] ;
int roll, age, regdno ;
float total, avg ;
etc……
for a individual student.
If we want to store the details of more than one student than we have to
declare a huge amount of variables and which are too much difficult to access
it. I.e/ the programs length will increased too faster. So it will be better to
declare the variables in a group. I.e/ name variable will be used for more than
one student, roll variable will be used for more than one student, etc.
So to declare the variable of same kind in a group is known as the Array
and the concept of array is used for this purpose only.

Definition: The array is a collection of more than one element of same


kind with a single variable name.

Types of Array:
The arrays can be further classified into two broad categories such as:

• One Dimensional (The array having one boundary


specification)
• Multi dimensional (The array having more than one bound-
ary specification)

Sachi Nandan Mohanty and Pabitra Kumar Tripathy. Data Structure and Algorithms Using C++:
A Practical Implementation, (15–48) © 2021 Scrivener Publishing LLC

15
16 Data Structure and Algorithms Using C++

2.1.1 One-Dimensional Array


Declaration:

Syntax :
Data type variable_name[bound] ;
The data type may be one of the data types that we are studied. The
variable name is also same as the normal variable_name but the bound is
the number which will further specify that how much variables you want
to combine into a single unit.
Ex : int roll[15];
In the above example roll is an array 15 variables whose capacity is to
store the roll_number of 15 students.
And the individual variables are
roll[0] , roll[1], roll[2], roll[3] ,……………..,roll[14]

Array Element in Memory


The array elements are stored in a consecutive manner inside the memory.
i.e./ They allocate a sequential memory allocation.
For Ex : int x[7];
Let the x[0] will be at the memory address 568 then the entire array can
be represented in the memory as

x[0] X[1] X[2] X[3] X[4] X[5] X[6]


568 570 572 574 576 578 580

Initialization:
The array is also initialized just like other normal variable except that
we have to pass a group of elements with in a chain bracket separated by
commas.
Ex : int x[5]= { 24,23,5,67,897 } ;
In the above statement x[0] = 24, x[1] = 23, x[2]=5, x[3]=67,x[4]=897
Review of Concepts of ‘C++’ 17

Retrieving and Storing Some Value From/Into the Array


Since array is a collection of more than one elements of same kind so while
performing any task with the array we have to do that work repeatedly.
Therefore while retrieving or storing the elements from/into an array we
must have to use the concept of looping.

Ex: Write a Program to Input 10 Elements Into an Array and


Display Them.

#include<iostream.h>
void main()
{
int x[10],i;
;
cout<<“\nEnter 10 elements into the array”;
for(i=0 ; i<10; i++)
cin>>x[i];
cout<<“\n THE ENTERED ARRAY ELEMENTS ARE :”;
for(i=0 ; i<10; i++)
cout<<” “<<x[i];
}

OUTPUT
Enter 10 elements into the array
12
36
89
54
6
125
35
87
49
6
 THE ENTERED ARRAY ELEMENTS ARE : 12 36
89 54 6 125 35 87 49 6

2.1.2 Multi-Dimensional Array


The array having more than one boundary specification is known as multi
dimensional array. The total number of elements to be stored in side a
multi dimensional array is equals to the product of its boundaries.
18 Data Structure and Algorithms Using C++

But we do use the two dimensional array to handle the matrix opera-
tions. The two dimensional array having two boundary specifications.

Declaration of Two-Dimensional Array


The declaration of the two dimensional array is just like the one dimen-
sional array except that instead of using a single boundary we have to use
two boundary specification.

SYNTAX
data_type variable_name[boundary1][boundary2];

Ex : int x[3][4];
In the above example x is the two dimensional array which has the capacity
to store (3x4) 12 elements. The individual number of elements are
x[0][0] x[0][1] x[0][2] x[0][3]
x[1][0] x[1][1] x[1][2] x[1][3]
x[2][0] x[2][1] x[2][2] x[2][3]

INITIALIZATION
The array can also be initialized as like one dimensional array.
Ex: int x[3][4] = {{3,5,7,8}, {45,12,34,3}, {56,89,56,23}};
OR
int x[3][4] = {3,5,7,8,45,12,34,3,56,89,56,23};
After the above initialization
x[0][0]=3 x[0][1]=5 x[0][2]=7 x[0][3]=8
x[1][0]=45 x[1][1]=12 x[1][2]=34 x[1][3]=3
x[2][0]=56 x[2][1]=89 x[2][2]=56 x[2][3]=23

Processing of a Two-Dimensional Array


While processing a two-dimensional array we have to use two loops.
Review of Concepts of ‘C++’ 19

Example : WAP to input a 3 x 3 matrix and find out the sum of


lower triangular elements.

#include<iostream.h>
void main()
{
int mat[3][3],i,j,sum=0;

/* INPUT THE ARRAY */

for(i=0 ; i<3 ; i++)


for(j=0 ; j<3 ; j++)
{
cout<<“\nEnter a number”;
cin>>mat[i][j];
}

/* LOGIC TO SUM THE LOWER TRIANGULAR ELEMENTS */

for(i=0 ; i<3 ; i++)


for(j=0 ; j<3 ; j++)
{
if(i>=j)
sum=sum+mat[i][j];
}

/* PRINT THE ARRAY */

cout“\nTHE ENTERED MATRIX IS\n”;


for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
cout<<” “<<mat[i][j];
}
cout<<“\n”;
}
cout<<“\nSum of the lower triangular matrix is”<<sum;
}
20 Data Structure and Algorithms Using C++

OUTPUT
Enter a number 5
Enter a number 7
Enter a number 9
Enter a number 2
Enter a number 6
Enter a number 8
Enter a number 12
Enter a number 24
Enter a number 7

THE ENTERED MATRIX IS


5 7 9
2 6 8
12 24 7
Sum of the lower triangular matrix is 56

2.1.3 String Handling


The string is a collection of more than one character. So it can also be called
as a character array. The approaching to the string/character array is some-
what different compare to the normal array due to its speciality nature.
The speciality is that the string always terminates with a NULL (‘\0’)
character. So while accessing the string there is no need to use the loop
frequently(We may access it as a array with the help of loop).
When we will access it with the loop (like int, float etc. array) than the
NULL character will not be assigned at the end of it, so while printing it
we are bound to use the loop again. If we want to convert the character
array to a string so we have to assign the NULL character at the end of it,
manually.
Representation of a string and a Character Array
Let char x[10]=”India”; /* Representation of a string*/

I n d i a \0
0 1 2 3 4 5 6 7 8 9
Review of Concepts of ‘C++’ 21

char x[10] = {‘I’,’n’,’d’,’i’,’a’}; /* Character Array */

I n d i a
0 1 2 3 4 5 6 7 8 9

Declaration of a Character Array


The declaration of the string/character array is same as the normal array,
except that instead of using other data type the data type ‘char’ is used.
Syntax : Data_type var_name[size] ;

Ex: char name[20];


Initialization of a String
Let char x[10]=”India”; /* Representation of a string*/

I n d i a \0
0 1 2 3 4 5 6 7 8 9

char x[10] = {‘I’,’n’,’d’,’i’,’a’}; /* Character Array */

Example: Wap to Input a string and display it.


#include<iostream.h>
void main()
{
char x[20];
cout<<"\nEnter a string";
gets(x);
cout<<"\n THE ENTERED STRING IS "<<x;
}

OUTPUT
Enter a string Hello
THE ENTERED STRING IS Hello
OR
22 Data Structure and Algorithms Using C++

This process of Input is not preferable because forcibly we are bound to


input the 10 characters, not less than 10 or above 10 characters.
#include<iostream.h>
void main()
{
char x[20];
int i;
cout<<"\nEnter a string";
for(i=0;i<10;i++)
cin>>x[i];
x[i]='\0'; /* CONVERTING THE CHARACTER ARRAY
TO STRING */
cout<<"\n THE ENTERED STRING IS "<<x;
}

OR
#include<iostream.h>
void main()
{
char x[20];
int i;
cout<<"\nEnter a string";
gets(x);
cout<<"\n THE ENTERED STRING IS ";
for(i=0; x[i]!=’\0’;i++)
cout<<x[i];
}

OUTPUT
Enter a string Hello
THE ENTERED STRING IS Hello

NOTE : If we want to scan a string as individual characters then we


have to use the loop as for(i=0; str[i]!='\0';i++)
This is fixed for all the strings after input it.
Review of Concepts of ‘C++’ 23

Example – 2
Write a program to input a string and count how many vowels are in it.
#include<iostream.h>
void main()
{
char x[20];
int i,count=0;
cout<<"\n Enter a string";
gets(x);
cout<<"\n The entered string is"<<x;
for(i=0; x[i]!='\0';i++)
if(toupper(x[i])=='A' || toupper(x[i])=='E'
|| toupper(x[i])=='I' || toupper​ (x[i])=='O' ||
toupper(x[i))=='U')
count++;
cout<<"\n The string"<<x<< "having"<<count<<"num-
bers of vowels";
}

OUTPUT
Enter a string Wel Come
The entered string is Wel Come
The string Wel Come having 3 numbers of vowels.

Example :
Write a program to find out the length of a string.
#include<iostream.h>
void main()
{
char x[20];
int i,len=0;
cout<<"\n Enter a string";
gets(x);
for(i=0;x[i]!='\0';i++)
len++;
cout<<"\n THE LENGTH OF"<<x<<"IS"<<len;
}
24 Data Structure and Algorithms Using C++

OUTPUT
Enter a string hello India
THE LENGTH OF hello India IS 11

OR
#include<iostream.h>
void main()
{
char x[20];
int i;
cout<<"\n Enter a string";
gets(x);
for(i=0;x[i]!='\0';i++) ;
cout<<"\n THE LENGTH OF"<<x<<"IS"<<len;
}

OUTPUT
Enter a string hello India
THE LENGTH OF hello India IS 11

String Manipulation
The strings cannot be manipulated with the normal operators, so to have
some manipulation we have to use the help of certain string handling
functions. ’C’-language provides a number of string handling functions
amongst them the most popularly used functions are

a. Strlen()
b. Strrev()
c. Strcat()
d. Strcmp()
e. Strcpy()
f. Strupr()
g. Strlwr()

These functions prototypes are declared inside the header file string.h
™™ Strlen()
Purpose : Used to find out the length of a string.
Syntax : integer_variable = strlen(string);
Review of Concepts of ‘C++’ 25

™™ Strrev()
Purpose : Used to find out the reverse of a string.
Syntax : strrev(string);

™™ Strcat()
Purpose: Used to concatenate(Join) two strings. It will
append the source string at the end of the destination. The
length of the destination will be the length of source + length
of destination
Syntax: strcat(destination,source);

™™ Strcmp()
Purpose: Used to compare two strings.
Process: The string comparison always starts with the first
character in each string and continuous with subsequent
characters until the corresponding characters differ or until
the end of a string is reached.

This function returns an integer value that is


ASCII VALUES
< 0 if s1 < s2 A = 65 a = 97
== 0 if s1 == s2 0 = 48
>0 if s1 > s2

The string comparison is always based upon the ASCII values of the
characters.
Syntax : integer_variable = strcmp(s1,s2);

™™ Strcpy()
Purpose :To copy a string to other.
Syntax : strcpy(destination,source);

™™ Strupr()
Purpose : To convert all the lower case alphabets to its cor-
responding upper-case.
Syntax : strupr(string);

™™ Strlwr()
Purpose : To convert all the upper case alphabets to its cor-
responding lower-case.
Syntax : strlwr(string);
26 Data Structure and Algorithms Using C++

2.2 Function
Definition: One or more than one statements combined together to form
a block with a particular name and having a specific task.
The functions in ‘C’ are classified into two types as

a. Library Function or Pre defined function


b. User defined function

The library functions are already comes with the ‘C’ compiler(Language).
Ex : printf(), scanf(), gets(), clrscr(), strlen() etc.
The user defined functions are defined by the programmer when ever
required.

2.2.1 User Defined Functions


We will develop the functions just comparison with the library functions,
i.e/ All the library functions can be categorized into four types as

1. integer variable = strlen(string/string variable)


[The strlen() takes a string ,find its length and returns it to a
integer variable]
2. gets(string variable);
[the gets() takes a variable and stores string inside that which
will be entered by the user]
3. character variable = getch();
[The getch() does not take any value/variable but it stores a
character into the character variable which will be entered
by the user]
4. clrscr();
[This function does not take argument and not return also,
but it does its work that means it clears the screen]

So by studying the above four types of functions we concluded that by


considering the arguments taken by the function and the values returned
by the functions the functions can be categorized into four types as

1. The function takes argument and also returns value.


2. The function does not take argument but returns value.
3. The function takes argument but not return value.
4. The function does not take argument and also not return values.
Review of Concepts of ‘C++’ 27

Parts of a Function
A function has generally three parts as

1. Declaration (Specifies that how the function will work, it


prepares only the skeleton of the function)
2. Call [It call the function for execution]
3. Definition [It specifies the work of the function i./ it is the
body part of the function]

2.2.2 Construction of a Function


1. Function takes argument and also returns value.
DECLARATION
Return_type function_name(data type, data_type, data_
type, …………….);
Ex: int sum(int,int);
CALL
Variable = function_name(var1,var2,var3,……………..);
Ex: x = sum(a,b);
Where a,b,x are the integer variables
DEFINITION
Return_type function_name(data_type var1, data_type
var2,………..)
{
Body of the function ;
Return(value/variable/expression);
}

Ex:
int sum(int p, int q)
{
int z;
z = p+q;
return(z);
}

2. Function does not take argument but returns value.


DECLARATION
Return_type function_name();
Or
28 Data Structure and Algorithms Using C++

Return_type function_name(void);
Ex : int sum();
CALL
Variable = function_name();
Ex : x = sum();
Where x is an integer.
DEFINITION
Return_type function_name()
{
Body of function;
Return(value/variable/expression);
}
Ex:
int sum()
{
int a,b;
cout<<"\nEnter 2 numbers";
cin>>a>>b;
return(a+b);
}

3. Function takes argument but not returns value


DECLARATION
void function_name(data type1,data type2,……………);

Ex : void sum(int,int);
CALL
function_name(var1,var2,var3…………);

Ex : sum(x,y);
Where x and y is an integer.

DEFINITION
Void function_name (data_type1 v1, data_type2 v2,………)
{
Body of function ;
}
Ex:
void sum(int x, int y)
{
cout<<"\nSum = "<<x+y;
}
Review of Concepts of ‘C++’ 29

4. Function does not take arguments and not returns value.


DECLARATION
void function_name(void);
Ex : void sum();
CALL
function_name();

Ex : sum();
DEFINITION
Void function_name ()
{
Body of function ;
}
Ex:
void sum()
{
int x,y;
cout<<"\n Enter two numbers";
cin>>x>>y;
cout<<"\nSum = "<<x+y;
}

ARGUMENTS : Based upon which the function works.


RETURN TYPE: The value returned /given by the function to its calling part.

WAP TO FIND OUT THE SUM OF TWO NUMBERS


Category – 1
#include<iostream.h>
void main()
{
int sum(int,int);
int x,y,z;
cout<<"\n Enter two numbers";
cin>>x>>y;
z = sum(x,y);
cout<<"\n Addition of"<<x<<"and"<<y<<"is"<<z;
}
int sum(int p, int q)
{
int r;
r = p+q;
return(r);
}
30 Data Structure and Algorithms Using C++

OUTPUT
Enter two numbers 5
6
Addition of 5 and 6 is 11

Category – 2
#include<iostream.h>
void main()
{
int sum();
int z;
z = sum();
cout<<"\n Addition is"<<z;
}
int sum()
{
int x,y;
cout<<"\n Enter two numbers";
cin>>x>>y;
return(x+y);
}

OUTPUT
Enter two numbers 5
6
Addition is 11

Category – 3
#include<iostream.h>
void main()
{
void sum(int,int);
int x,y;
cout<<"\n Enter two numbers";
cin>>x>>y;
sum(x,y);
}
void sum(int p,int q)
{
Cout<<“\n Addition
of”<<p<<”and”<<q<<”is”<<p+q;
}
OUTPUT
Enter two numbers 5
6
Addition of 5 and 6 is 11
Review of Concepts of ‘C++’ 31

Category – 4
#include<iostream.h>
void main()
{
void sum();
sum();
}
void sum()
{
int x,y;
cout<<"\n Enter two numbers";
cin>>x>>y;
cout<<"Addition of"<<x<<"and"<<y<<"is"<<x+y;
}

OUTPUT
Enter two numbers 5
6
Addition of 5 and 6 is 11

2.2.3 Actual Argument and Formal Argument


Those arguments kept inside the function call is known as actual argument
and those arguments kept inside the function definition is known as the
formal arguments (Because these are used to maintain the formality just to
store the values of the actual arguments).

Ex:
#include<iostream.h>
void main()
{
int sum(int,int);
int x,y,z;
cout<<"\n Enter two numbers";
cin>>x>>y;
z = sum(x,y); /* Here x and y are called as the
actual argument*/
cout<<"\n Addition of"<<x<<"and"<<y<<"is"<<z;
}
int sum(int p, int q) /* Here p and q are called as the formal
argument */
{
int r;
r = p+q;
return(r);
}
32 Data Structure and Algorithms Using C++

OUTPUT
Enter two numbers 5
6
Addition of 5 and 6 is 11

If a function is to use arguments, it must declare variables that accept the


values of the arguments. These variables are called the formal parameters
of the function.
The formal parameters behave like other local variables inside the func-
tion and are created upon entry into the function and destroyed upon exit.
While calling a function, there are two ways that arguments can be
passed to a function:

Call Type Description


Call by value This method copies the actual value of an argument into
the formal parameter of the function. In this case,
changes made to the parameter inside the function
have no effect on the argument.
Call by pointer This method copies the address of an argument into the
formal parameter. Inside the function, the address is
used to access the actual argument used in the call.
This means that changes made to the parameter affect
the argument.
Call by reference This method copies the reference of an argument into the
formal parameter. Inside the function, the reference
is used to access the actual argument used in the call.
This means that changes made to the parameter affect
the argument.

By default, C++ uses call by value to pass arguments. In general, this


means that code within a function cannot alter the arguments used to call
the function and above mentioned example while calling max() function
used the same method.

2.2.4 Call by Value and Call by Reference


When a function is called by its value then that function call is known as
call by value.
When a function is called by its reference/address then that function call
is known as call by reference.
Review of Concepts of ‘C++’ 33

Difference Between Call by Value and Call by Reference


In call by value if the value of the variable is changed inside the function
than that will not effect to its original value, because the value of the actual
parameters are copied to the formal arguments so there is no interlink
between them.
But in call by reference if the value of the variable is changed inside
the function then that will be effected to its original value, because in call
by reference the addresses of the actual arguments are copied to the for-
mal arguments that’s why there is a interlink between them. So any change
made with the formal argument then that will effect to the actual value.

Ex:
Call by value
#include<iostream.h>
void main()
{
int x=5,y=6;
void change(int,int);
cout<<“\n X=”<<x<<”and Y=”<<y;
change(x,y);
cout<<“\n X=”<<x<<”and Y=”<<y;
}
void change(int a,int b)
{
a=a+5;
b=b+5;
cout<<“\n X=”<<a<<”and Y=”<<b;
}

OUTPUT
X = 5 and Y=6
X=10 and Y=11
X=5 and Y=6
Call by REFERENCE
#include<iostream.h>
void main()
{
int x=5,y=6;
void change(int *,int *);
34 Data Structure and Algorithms Using C++

cout<<“\n X=”<<x<<”and Y=”<<y;


change(&x,&y);
cout<<“\n X=”<<x<<”and Y=”<<y;
}
void change(int *a,int *b)
{
*a=*a+5;
*b= *b+5;
cout<<“\n X=”<<*a<<”and Y=”<<*b;
}

OUTPUT
X = 5 and Y=6
X=10 and Y=11
X=10 and Y=11

2.2.5 Default Values for Parameters


When you define a function you can specify a default value for each of the
last parameters. This value will be used if the corresponding argument is
left blank when calling to the function.
This is done by using the assignment operator and assigning values for
the arguments in the function definition. If a value for that parameter is
not passed when the function is called, the default given value is used, but
if a value is specified this default value is ignored and the passed value is
used instead. Consider the following example:
#include <iostream>

int sum(int a, int b=20)


{
int result;

result = a + b;

return (result);
}

int main ()
{
// local variable declaration:
int a = 100;
int b = 200;
int result;
Review of Concepts of ‘C++’ 35

// calling a function to add the values.


result = sum(a, b);
cout << "Total value is :" << result << endl;

// calling a function again as follows.


result = sum(a);
cout << "Total value is :" << result << endl;

return 0;
}
When the above code is compiled and executed, it produces following
result:
Total value is :300
Total value is :120

2.2.6 Storage Class Specifiers


The storage class specifiers are the keywords which are used to declare the
variables. Without the help of storage class specifier we cannot declare the
variables but till now we declare the variables without using the storage
class specifier. Because by default the c-language includes the variable into
‘auto’ storage class.
‘C++’-language supports four storage class specifiers as auto, static,
extern, register
AUTO
Initial Value : Garbage value
Storage Area : Memory
Life : With in the block where it is declared
Scope : Local
STATIC
Initial Value : Zero
Storage Area : Memory
Life : With in the block where it is declared
Scope : 
The value of the variable will persist
between different function calls
EXTERN
Initial Value : Zero
Storage Area : Memory
Life :  The variable can access any where of
the program
Scope : Global
36 Data Structure and Algorithms Using C++

REGISTER
Initial Value : Garbage
Storage Area : CPU Memory
Life : With in the block where it is declared
Scope : Local
Difference between STATIC and AUTO
#include<stdio.h>
void main()
{
void change();
change();
change();
change();
}
Void change()
{
auto int x=0;
printf(“\n X= %d”,x);
x++;
}
OUTPUT
X=0
X=0
X=0
#include<stdio.h>
void main()
{
void change();
change();
change();
change();
}
Void change()
{
static int x;
printf("\n X= %d",x);
x++;
}
OUTPUT
X=0
X=1
X=2
Review of Concepts of ‘C++’ 37

2.3 Pointer
The pointer is a variable which can store the address of another variable.
Whatever changed with the value of the variable with the help of the
pointer that will directly effect to it.

2.3.1 Declaration of a Pointer


Like other variables the pointer variable should also be declared before its
use
SYNTAX
Data_type *variable_name;
Example: int *p;

2.3.2 Initialization of a Pointer


Initialization means to assign an initial value, since the pointer can store
only the address so during its initialization we have to assign an address of
another variable.
Ex: int *x,p;
X=&p; /* INITIALIZATION */

NOTE : After declaration of the pointer variable, if we write simply


the variables name than it will represent to address and *variable
will represent to value. But in C++ always we have to use *variable
since it deals with object.

Example :(IN C)
WRITE A PROGRAM TO INPUT A NUMBER AND DISPLAY IT.
#include<iostream.h>
void main() INSIDE MEMORY
{ P X
int *p,x; P=&X
1087 5
p=&x;
printf(“\n Enter a number”);
scanf(“%d”,&x);
732 1087 P = 1087, *P=5
X=5 AND &X = 1087

printf(“\n THE VALUE OF X(THROUGH POINTER) IS %d”,*p);


printf(“\n THE VALUE OF X IS %d”,x);
}
38 Data Structure and Algorithms Using C++

OUTPUT
Enter a number 5

THE VALUE OF X(THROUGH POINTER) IS 5


THE VALUE OF X IS 5
(IN C++)
WRITE A PROGRAM TO INPUT A NUMBER AND DISPLAY IT.
#include<iostream.h>
void main() INSIDE MEMORY
{ P X
int *p,x; 1087 5 P=&X
p=&x;
cout<<”\n Enter a number”;
732 1087 P = 1087, *P=5
cin>>*x;
X=5 AND &X = 1087
cout<<”\n THE VALUE OF X(THROUGH POINTER) IS ”<<*p;
cout<<”\n THE VALUE OF X IS”<<*x;
}
OUTPUT
Enter a number 5

THE VALUE OF X(THROUGH POINTER) IS 5


THE VALUE OF X IS 5

2.3.3 Arithmetic With Pointer


In general the arithmetic operations include Addition, Subtraction, Multi­
plication, and Division. But in case of pointer we can perform only the addi-
tion and subtraction operations. That means when we perform an addition/
subtraction operation with the pointer then it shifts the locations because
pointer means an address. If we add one to the integer pointer then it will
shift two bytes (int occupies two bytes in memory), so for float 4 bytes, char
1 byte, long double 4 bytes and accordingly it will shift the positions.
Ex: Let int *p,x ;
P=&x; x p
756
756 1065
Now p = 756
P + 1 = 758
P + 2 = 760
P+5 = 766
p-6 = 754
Review of Concepts of ‘C++’ 39

NOTE : Pointer means the address so we can perform any type of opera-
tion with *p (value at address)

2.3.4 Passing of a Pointer to Function


As like normal variables we can also pass a pointer to the function as its
argument.

DECLARATION
Return_type function_name(data_type *, data_type *,…………);

CALL
Variable = function_name(ptrvar, ptrvar, ptrvar,………);

DEFINITION
Return_type function_name(data_type *var, data_type *var,…………)
{
body of function ;
return(value/var/exp);
}
Example:
WRITE A PROGRAM TO FINDOUT THE FACTORIAL OF A NUMBER
#include<iostream.h>
void main()
{
long int fact(int *);
int *n;
long int f;
cout<<“\n Enter a number”;
cin>>*n;

f=fact(n);
cout<<“\n Factorial Is”<<f;
}
long int fact(int *p)
{
int i;
long int f=1;
for(i=1;i<=*p;i++)
f*=i;
return(f);
}
Other documents randomly have
different content
[122] Cunningham, vol. i. p. 26.
[123] Ibid. p. 757.
[124] Ibid.
[125] Walpole’s Anecdotes, vol. i. p. 282.
[126] Galt’s Life of West, pt. ii. p. 25.
[127] Ibid. pp. 36-38.
[128] Strange’s Enquiry into the Rise and Establishment of the Royal
Academy (1775).
[129] Pye’s Patronage of British Art, p. 134.
[130] The original thirty-six Academicians were—Benjamin West,
Francesco Zuccarelli, Nathaniel Dance, Richard Wilson, George
Michael Moser, Samuel Wale (a sign-painter), J. Baptist Cipriani,
Jeremiah Meyer, Angelica Kauffmann, Charles Catton (a coach and
sign painter), Francesco Bartolozzi, Francis Cotes, Edward Penny,
George Barrett (Wilson’s rival), Paul Sandby, Richard Yeo, Mary
Moser, Agostino Carlini, William Chambers (the architect of Somerset
House), Joseph Wilton (the sculptor), Francis Milner Newton, Francis
Hayman, John Baker, Mason Chamberlin, John Gwynn, Thomas
Gainsborough, Dominick Serres, Peter Toms (a drapery painter for
Reynolds, who finally committed suicide), Nathaniel Hone (who for
his libel on Reynolds was expelled the Academy), Joshua Reynolds,
John Richards, Thomas Sandby, George Dance, J. Tyler, William
Hoare of Bath, and Johann Zoffani. In 1772 Edward Burch, Richard
Cosway, Joseph Nollekens, and James Barry (expelled in 1797),
made up the forty.—Wornum’s Preface to the Lectures on Painting.
[131] Pye’s Patronage of British Art, 1845, p. 136.
[132] Royal Academy Catalogues, Brit. Mus.
[133] Smith’s Nollekens, vol. i. p. 381.
[134] Life of Haydon, by Tom Taylor, vol. i. p. 30.
[135] Ibid. p. 20.
[136] Thornbury’s Life of Turner.
[137] O’Keefe’s Life vol. i. p. 386.
[138] Knowles’s Life of Fuseli, vol. i. p. 32.
[139] Irvine’s Life of Falconer.
[140] Smith’s Life of Nollekens, vol. ii. p. 129.
[141] Hatton, p. 785.
[142] Postman, No. 80.
[143] Life of Blake, by Gilchrist.
[144] Andrews’s History of Journalism, vol. ii. p. 85.
[145] Strype, B. iii. p. 196.
[146] Glover’s Life, p. 6.
[147] Dennis’s Letters, p. 196.
[148] Procter’s Life of Kean, vol. ii. p. 140.
[149] Dr. King’s Art of Cookery.
[150] Spectator, No. 9.
[151] Memoirs of the Kit-Cat Club, p. 6.
[152] Defoe’s Journal, vol. i. p. 287.
[153] Letters of Lady M. W. Montagu, edited by W. M. Thomas, Esq.
[154] Annual Obituary, vol. vii.
[155] Monthly Repository, by Leigh Hunt, 1836.
[156] Procter’s Life of Kean.
[157] The Temple Anecdotes (Groombridge), p. 50.
[158] Strype, B. iv. p. 120.
[159] Ibid.
[160] Dixon’s Bacon, p. 227.
[161] Appendix to the Tatler, vol. iv. p. 615.
[162] Smith’s Streets of London, vol. iv. p. 244.
[163] Egerton Papers, by Collier, p. 376.
[164] Strype, B. vi. p. 76.
[165] Cunningham, vol. i. p. 283.
[166] London Gazette, No. 897.
[167] Pepys, vol. i. p. 137, 4to ed.
[168] Horace Walpole.
[169] Otway.
[170] Spectator, No. 155.
[171] Tatler, No. 26.
[172] Nouvelle Biographie Univ., vol. xxxviii. p. 19.
[173] Ducatus Leodiensis, fol. 1715, p. 485.
[174] British Apollo (1740), ii. p. 376.
[175] Oldys’s Life of Raleigh, p. 145.
[176] Aubrey, vol. iii. p. 513.
[177] Gough’s British Topography, vol. i. p. 743.
[178] Walpole’s Mems. of George III., vol. iv. p. 173.
[179] Elmes’s Anecdotes, vol. iii.
[180] Cunningham, vol. i. p. 83.
[181] Boswell, vol. i. p. 225.
[182] Hone’s Everyday Book, vol. i. p. 237.
[183] Pye’s Patronage of British Art (1845), pp. 61, 62.
[184] Wine and Walnuts, vol. i. p. 161.
[185] Smith’s Nollekens, vol. i. p. 3.
[186] Ibid. vol. ii. p. 203.
[187] Haydon’s Life, vol. iii. p. 182.
[188] Book about Doctors, by J. C. Jeaffreson, p. 221.
[189] Archenholz, p. 109.
[190] Colman’s Random Records.
[191] See the Percy Society’s Publications.
[192] Rymer, iii. 926.
[193] Chaucer’s Works.
[194] Dugdale’s Baronetage, vol. 1. p. 789.
[195] Scala Chron., p. 175; Froissart, c. 161.
[196] Rymer, vi. 452.
[197] Froissart, lix.
[198] Walsingham, p. 248.
[199] Holinshed, vol. ii. p. 431.
[200] Shakspere incorrectly makes Jack Cade burn the Savoy. He
has attributed to that Irish impostor the act of Wat Tyler, a far more
patriotic man.
[201] Stow.
[202] Cowley’s Works, 10th edit. (Tonson), 1707, vol. ii. p. 587.
[203] Letter to Evelyn. Cowley’s Works (1707), vol. ii. p. 731.
[204] J. T. Smith’s Antiquarian Ramble in the Streets of London
(1846), vol. i. p. 255.
[205] Baker’s Chronicle (1730), p. 625.
[206] Cunningham’s London (1849), vol. ii. p. 728.
[207] The Postman (1696), No. 180.
[208] Strype, B. iv. p. 107, ed. 1720.
[209] Hughson’s Walks through London, p. 207.
[210] Hughson’s Walks through London, p. 209.
[211] Dryden’s Works (1821 ed.), vol. ii. p. 105.
[212] Athenæ Ox. vol. ii. p. 1036.
[213] Cunningham (1849), vol. ii. p. 537.
[214] Wood’s Athen. Ox. ii. 396, ed. 1721.
[215] The Shepherd’s Hunting (1633).
[216] Macaulay’s History of England, vol. ii. chap. v.
[217] Buckingham’s Works (1704), p. 15.
[218] All the Year Round, May 12, 1860 (The Precinct).
[219] Andrews’s History of British Journalism, vol. ii. p. 83.
[220] Smiles’s Lives of the Engineers, vol. ii. p. 187.
[221] Smiles’s Lives of the Engineers, vol. ii. p. 186.
[222] Ibid., vol. ii. p. 93.
[223] Hepworth Dixon’s Story of Lord Bacon’s Life (1862), p. 14.
[224] Montagu, xii. 420, 432.
[225] Aubrey’s Lives, vol. ii. p. 224; Dixon’s Bacon, p. 315.
[226] Character of Lord Bacon.
[227] Dixon’s Story of Lord Bacon’s Life, p. 33 (1862). Pearce’s Inns
of Court.
[228] Sir B. Gerbier.
[229] Bassompierre’s Embassy to England.
[230] Whitelocke, p. 167.
[231] Peacham’s Compleat Gentleman, ed. 1661, p. 108.
[232] Pepys, 6th June 1663.
[233] Dryden (Scott), vol. ix. p. 233.
[234] Pepys’s Diary. vol. i. p. 223.
[235] Evelyn’s Memoirs, vol. i. p. 530.
[236] Rate Books of St. Martin’s.
[237] Cole’s MSS., vol. xx. folio 220.
[238] Gilchrist’s Life of Etty, vol. i. p. 221.
[239] Barrow’s Life of Peter the Great, p. 90.
[240] Ballard’s Collection, Bodleian.
[241] Pennant.
[242] Strype, B. vi. p. 76.
[243] Cunningham, vol. i. pp. 402, 403.
[244] Rate-books of St. Martin’s.
[245] Memorials of Franklin, vol. i. p. 261.
[246] Smith’s Comic Misc. vol. ii. p. 186.
[247] Memoirs of James Smith, by Horace Smith, vol. i. p. 32.
[248] Memoirs of James Smith, by Horace Smith, vol. i. p. 54.
[249] Smith’s Nollekens, vol. i. p. 340.
[250] Ibid. vol. i. pt 302.
[251] Harl. MSS. 6850.
[252] Rate-books of St. Martin’s.
[253] Smith’s Book for a Rainy Day, pp. 281, 282.
[254] Cal. Rot. Patentium.
[255] Brayley’s Beauties of England and Wales, vol. x. part iv. p. 167.
[256] Father Hubbard’s Tale, 4to, 1604.—Middleton’s Works, vol. v.
p. 573.
[257] Archer’s Vestiges of Old London (View of Crockford’s shop).
[258] Walpole’s Anecdotes, vol. iii. p. 911.
[259] Malcolm’s Londinum Rediviv. vol. iii. p. 397.
[260] Hughson’s Walks (1829).
[261] Boswell’s Life of Johnson, vol. i. p. 383.
[262] Boswell, vol. iii. p. 331.
[263] Censura Literaria, vol. i. p. 176.
[264] Spence’s Anecdotes.
[265] State Poems, vol. ii. p. 143 (“A Satyr on the Poets.”)
[266] Leigh Hunt’s Town (1857), p. 135.
[267] Hughson’s Walks, p. 184.
[268] Leigh Hunt’s Town (1859 ed.), p. 134.
[269] Strype, B. iv. p. 117.
[270] Boswell.
[271] Walpole’s Anecdotes (ed. Dallaway), vol. ii. p. 315.
[272] Leigh Hunt’s Town (1859), p. 145.
[273] Brayley’s Beauties of England and Wales, vol. x. part iv. p. 166.
[274] Malone’s Shakspere, vol. iii. p. 516.
[275] Nichols’s Hogarth, vol. ii. p. 70.
[276] Cunningham (1849), vol. i. p. 210.
[277] Hughson’s Walks through London, p. 188.
[278] Chalmers’s Biog. Dict. vol. v. p. 64.
[279] Boswell, ed. Croker, vol. ii. 201.
[280] Stow, p. 166.
[281] Sir G. Buc, in Howes (ed. 1631), p. 1075.
[282] Fitzstephen, circa, 1178: the quotation refers, however, more
to the north of London.
[283] Tennyson.
[284] Malcolm’s London, vol. ii.
[285] Knox’s Elegant Extracts.
[286] Leigh Hunt’s Town, p. 146.
[287] Henry IV. second part, act iii. sc. 2.
[288] Prot. Dissenters’ Magazine, vol. vi.
[289] Smith’s Life of Nollekens, vol. i. 365.
[290] Cradock’s Memoirs, vol. iv. p. 166.
[291] Garrard to the Earl of Strafford, vol. i. p. 227.
[292] Citie’s Loyaltie Displayed, 4to, 1661.
[293] Pepys.
[294] Aubrey’s Anecdotes, vol. iii. p. 457.
[295] Malcolm’s Streets of London (1846), vol. i. p. 363.
[296] Parish Clerks’ Survey, p. 286.
[297] Cunningham’s Lives of the Painters, vol. iii. p. 292.
[298] Pope’s Dunciad.
[299] Addison’s Freeholder, No. 4.
[300] J. T. Smith’s Streets of London (1846), vol. i. pp. 366, 367.
[301] Sir G. Buc (Stow by Howes), p. 1075, ed. 1631.
[302] Roper’s Life of Sir Thomas More, by Singer, p. 52.
[303] Spectator No. 2, March 2, 1710-11.
[304] Cunningham, vol. ii. p. 606.
[305] Sir G. Buc, in Howes, p. 1076, ed. 1631.
[306] Trivia.
[307] Smith’s Streets of London, vol. i. p. 338.
[308] Hone’s Every-day Book, vol. i. p. 1300.
[309] Walpole’s Anecdotes of Painting, vol. ii. p. 612.
[310] No. 102.
[311] Pennant’s London (1813), p. 204.
[312] Spectator, No. 454.
[313] Spectator, No. 454.
[314] Andrews’s History of Journalism, vol. ii. p. 8.
[315] Brayley’s Theatres of London (1826), p. 40.
[316] Brayley, p. 42.
[317] Chetwood’s History of the Stage, p. 141.
[318] Spectator, No. 468.
[319] Ward’s Secret History of Clubs, ed. 1709.
[320] Victor.
[321] Edwards’s Anecdotes of Painting, p. 20.
[322] Wine and Walnuts, vol. i. p. 110.
[323] P. Cunningham.
[324] Dr. King’s Art of Cookery, humbly inscribed to the Beef-steak
Club. (1709.)
[325] Leigh Hunt’s Town (1859), p. 191.
[326] Cunningham, vol. i. p. 297.
[327] Delaune.
[328] Strype, B. iv. p. 119.
[329] Leigh Hunt’s Town, ch. iv.
[330] Wine and Walnuts, vol. i. p. 281.
[331] Ibid. p. 269.
[332] Wine and Walnuts, vol. i. p. 276.
[333] Cunningham, p. 187.
[334] Whitelocke.
[335] Lockhart’s Life of Scott, vol. vi. p. 20.
[336] The Stage, by Alfred Bunn, vol. iii. p. 131.
[337] Life of Mathews, by Mrs. Mathews (abridged by Mr. Yates), p.
211.
[338] Life of Mathews, by Mrs. Mathews.
[339] Critical Essays (1807), p. 140.
[340] Hazlitt’s Criticisms of the English Stage, p. 98.
[341] Hazlitt’s Criticisms of the English Stage, p. 98.
[342] Cole’s Life of C. Kean, vol. ii. p. 260.
[343] Strype, B. vi. p. 93.
[344] Stow.
[345] Davies’s Life of Garrick, vol. x. p. 217.
[346] Strype, B. vi. p. 93.
[347] Cunningham’s London (1850), p. 219.
[348] Whyte’s Miscellanea Nova, p. 49.
[349] Cunningham, vol. ii. p. 597.—Rate-books of St. Martin’s.
[350] Walpole’s Anecdotes, vol. i. p. 248.
[351] Dixon’s Story of Lord Bacon’s Life, p. 204.
[352] English Causes Célèbres (edited by Craik), vol. i. p. 79.
[353] Memoirs of the Peers of James I., p. 240.
[354] Autobiography of Lord Herbert, p. 110
[355] Suckling’s Poems.
[356] Camden’s Annals of King James.
[357] Londinum Redivivum.
[358] Walpole to Montague, Feb. 2, 1762.
[359] Dix’s Life of Chatterton, p. 267.
[360] Foster’s Life of Goldsmith, p. 216.
[361] Irving’s Oliver Goldsmith (1850), p. 90.
[362] Dr. Waagen’s Treasures of Art, vol. i. p. 394.
[363] Walpole’s Anecdotes, vol. ii. p. 354.
[364] Walpole, vol. i. p. 277.
[365] The Famous Chronicle of King Edward I. (4to., 1593).
[366] Bosworth’s Anglo-Saxon Dictionary.
[367] Hamlet.
[368] Diversions of Purley.
[369] Peele’s Works (Dyce), vii. 575.
[370] Rymer, ii. 498.
[371] Heming, 590.
[372] Walpole, vol. i. p. 32.
[373] Gleanings from Westminster Abbey, 2d edition, p. 152 (W.
Burges), Roxburghe Club.
[374] Lilly’s Observations.
[375] Carlyle’s Cromwell, vol. i. p. 99.
[376] State Trials, vol. v. pp. 1234-5.
[377] Narcissus Luttrell.
[378] Overseers’ Books (Cunningham, vol. i. p. 179).
[379] Harl. MSS. 7315.
[380] Carpenter (quoted by Walpole, Anecdotes, vol. ii. p. 395).
[381] Walpole’s Anecdotes, vol. ii. p. 394.
[382] Smith’s Streets of London, vol. i. p. 139.
[383] Archenholz, Tableau de l’Angleterre, vol. ii. p. 164, 1788.
[384] Burnet, vol. ii. p. 53, ed. 1823.
[385] Annual Register (1810).
[386] Cobbett’s State Trials, vol. xvii. p. 160.
[387] Archenholz, vol. i. p. 166.
[388] Daily Advertiser, 1731.
[389] Gentleman’s Magazine, vol. i.
[390] v. 85.
[391] Hogarth’s Works (Nicholls and Steevens), vol. i. p. 162.
[392] Smith’s London, vol. i. p. 141.
[393] Notes and Queries (vol. vi., 1858), p. 364.
[394] Dunciad, B. iv. 30.
[395] Pope’s Works (edited by R. Carruthers), vol. ii. p. 314.
[396] Stow, p. 167.
[397] Report, May 16, 1844.
[398] Smith’s London, vol. i. p. 133.
[399] Dr. Waagen, vol. i. p. 6.
[400] Waagen, vol. i. p. 322.
[401] Ibid. vol. i. p. 331.
[402] Cunningham, nearly always correct, says £10,000 (vol. ii. p.
577).
[403] Waagen, vol. ii. p. 329.
[404] Cunningham’s London, p. 428.
[405] Smith’s Streets of London, vol. i. p. 153.
[406] Rate-books of St. Martin’s (Cunningham).
[407] MSS., Birch, 4221, quoted in the notes of the Tatler.
[408] “Country Wife.”
[409] “The Scowrers.”
[410] State Poems.
[411] “The Hind and the Panther Transversed.”
[412] “The Relapse.”
[413] The Art of Cookery.
[414] Weekly Journal, Nov. 21, 1724.
[415] London Gazette, June 4, 1688.
[416] Dunciad, B. ii. v. 411.
[417] Flying Post, June 23, 1716.
[418] Pope’s Works (Carruthers), vol. ii. pp. 309, 310.
[419] Leigh Hunt’s Essays on the Theatres (1807), p. 64.
[420] Philips’s Life of Milton, p. 32, 12mo, 1694.
[421] Cunningham (1850), p. 107.
[422] Wine and Walnuts, vol. i. p. 163.
[423] Royal Guide to the London Charities, 1878-79.
[424] Life of Dr. John North.
[425] Whitelock, p. 470, ed. 1732.
[426] Burnet, vol. ii. p. 70, ed. 1823.
[427] Boswell (Croker), vol. iii. p. 213.
[428] Willis’s History of the See of Llandaff.
[429] Bartholomew Fair (Ben Jonson).
[430] Gifford’s Ben Jonson, iv. p. 430.
[431] Cunningham, vol. ii. p. 505.
[432] The World, Nov. 29, 1753.
[433] Robson: a Sketch (Hotten, 1864).
[434] Aubrey, iii. 415.
[435] “Treacherous Brothers,” 4to, 1696.
[436] St. James’s Chronicle, April 24, 1762.
[437] Ibid. May 26, 1761.
[438] Edwards’ Anecdotes, pp. 116, 117.
[439] Rate-books of St. Martin’s.
[440] Lord Orford’s Anecdotes of Painting.
[441] J. C. Jeaffreson’s Book about Doctors, p. 109.
[442] Ath. Ox. vol. ii.
[443] Gifford’s Ben Jonson, vol. ix. pp. 48, 63, 64.
[444] Aubrey’s Letters, vol. ii. p. 332.
[445] Recital in grant to the parish from King James I.
[446] Cunningham’s London (1849), vol. ii. p. 526.
[447] Burnet’s Own Times, vol. i. p. 327, ed. 1823.
[448] Allan Cunningham’s Lives, vol. iv. p. 290.
[449] Biog. Brit.
[450] Smith’s Life of Nollekens, vol. ii. p. 233.
[451] Smith’s Book for a Rainy Day, pp. 251, 252.
[452] Prologues to the Satires, v. 180.
[453] Dr. Johnson’s Life of Ambrose Philips.
[454] Smith’s Nollekens and his Times, vol. ii. p. 222.
[455] Cunningham (1850), p. 450.
[456] Smith’s Streets, vol. ii. p. 208.
[457] Smith, vol. ii. p. 97.
[458] Smith, p. 211.
[459] Ibid. vol. ii. p. 212.
[460] Smith, vol. ii. p. 224.
[461] Smith’s Streets of London, vol. ii. p. 226.
[462] Wine and Walnuts, vol. i. p. 178, a curious and amusing book,
the truth in which is spoiled by an injudicious and eccentric mixture
of fiction.
[463] Smith’s Nollekens, vol. i. pp. 93, 94.
[464] Ibid. vol. ii. p. 233.
[465] Smith’s Nollekens, vol. ii. p. 238.
[466] Ibid. p. 241.
[467] Smith’s Nollekens, vol. i. p. 143.
[468] Ibid. vol. ii. p. 244.
[469] Ibid. p. 250.
[470] Recollections of O’Keefe, vol. i. p. 108.
[471] Knowles’s Life of Fuseli, vol. i. p. 57.
[472] Passages of a Working Life, by Charles Knight, vol. i. pp. 114,
115.
[473] Hume’s Learned Societies, pp. 84, 85.
[474] Dr. Hodges’ Letter to a Person of Quality, p. 15.
[475] Defoe’s Journal of the Plague Year.
[476] Dr. Hodges’ Loimologia, p. 7 (from the reprint in 1720, when
the plague was raging in France).
[477] Ibid. pp. 19, 20.
[478] Howes, p. 1048.
[479] Bagford, Harl. MSS. 5900, fol. 50.
[480] Walpole’s Royal and Noble Authors, vol. ii. p. 25.
[481] Evelyn’s Diary (1850), vol. ii. p. 59.
[482] Evelyn’s Diary, vol. ii. p. 153 (1850).
[483] Life of Lord Herbert (1826), p. 304.
[484] Horace Walpole.
[485] Aubrey’s Lives, vol. ii. p. 387.
[486] Walpole’s Anecdotes of Painting (Dallaway), vol. ii. p. 593.
[487] Richardson.
[488] Walpole, vol. ii. p. 563 (partly from Dallaway’s version of the
same story).
[489] Dallaway.
[490] Walpole, vol. ii. p. 594.
[491] Spence.
[492] Aubrey, vol. ii p. 132.
[493] Dallaway’s Notes.
[494] Clarendon, B. ii. p. 2117.
[495] Ibid. B. i. p. 116.
[496] Clarendon, B. viii. p. 694.
[497] Walpole’s Anecdotes of Painting, vol. ii. p. 452.
[498] Doran’s Her Majesty’s Servants, vol. ii. p. 51.
[499] Leigh Hunt’s Town, p. 226.
[500] Ibid. p. 226.
[501] Hazlitt’s Criticisms of the English Stage, p. 49.
[502] O’Keefe’s Life, vol. i. p. 322.
[503] Leigh Hunt, p. 226.
[504] Life of Benjamin Franklin (1826), p. 31.
[505] Life of the Duke of Ormond (1747), pp. 67, 80.
[506] Macaulay, vol. ii. p. 560.
[507] Bramston, p. 339.
[508] Annual Register (1780), pp. 254-287.
[509] Life of Inigo Jones, by P. Cunningham, p. 22 (Shakspere
Society).
[510] Smith’s Nollekens, vol. ii. p. 90.
[511] Cibber’s Lives, vol. ii. p. 10.
[512] Ibid. p. 11.
[513] Cunningham’s London, vol. ii. p. 501.
[514] Dryden’s Works (Scott), vol. i. p. 204.
[515] Scott’s Dryden, vol. xiii. p. 7.
[516] Cibber’s Lives, vol. iv. p. 293.
[517] Wine and Walnuts, vol. ii. p. 277.
[518] Cibber’s Lives, vol. iv. p. 47.
[519] Cibber’s Lives, vol. iv. p. 47.
[520] Mrs. Bray’s Life of Stothard, p. 47.
[521] Defoe’s Journey through England.
[522] Wine and Walnuts, vol. ii. p. 167.
[523] Smith’s Nollekens, vol. i. p. 27.
[524] Times, Sept. 26, 1796.
[525] Talfourd’s Final Memorials of Charles Lamb, vol. i. p. 56.
[526] Burke’s Landed Gentry (1858), p. 320.
[527] Pennant.
[528] Lingard, vol. vi. p. 607.
[529] Walton’s Lives (1852), p. 22.
[530] Angel in the House, by Mr. Coventry Patmore.
[531] Dedication to Translation of Juvenal.
[532] Donne’s Poems (1719), p. 291.
[533] Miss Benger’s Memoirs of the Queen of Bohemia, vol. ii. p.
322.
[534] Miss Benger’s Memoirs of the Queen of Bohemia, vol. ii. p.
428.
[535] Sydney State Papers, vol. ii. p. 723.
[536] Benger, vol. ii. p. 457.
[537] Ibid., Preface.
[538] Brayley’s Londiniana, vol. iv. p. 301.
[539] Walpole’s Anecdotes, p. 210.
[540] Cunningham, vol. i. p. 204.
[541] Wilson’s Life of James I. (1653), p. 146.
[542] Aubrey’s Anecdotes and Traditions, p. 3.
[543] Trivia.
[544] Rate-books of St. Martin’s, quoted by P. Cunningham.
[545] Granger’s Biographical History of England (1824), vol. v. p.
356.
[546] Pepys’s Memoirs, vol. iii. p. 75.
[547] Curll’s History of the English Stage, vol. i. p. III.
[548] Miscellaneous Works by the late Duke of Buckingham, etc., p.
35 (1704).
[549] Miscellaneous Works by the late Duke of Buckingham, etc.,
vol. i. p. 34.
[550] Burnet’s History of his own Times (1753), vol. i. p. 387.
[551] Leigh Hunt’s Town (1859), p. 282.
[552] Evelyn’s Mems. vol. ii. p. 339.
[553] Collier, iii. 328.
[554] Prynne’s Histrio-Mastix (1633).
[555] Pepys (May 8, 1663).
[556] Cibber’s Apology, p. 338. ed. 1740.
[557] Doran, vol. i. p. 57.
[558] Dec. 7, 1666.
[559] Jan. 23, 1667.
[560] April 20, 1667.
[561] Doran, p. 97.
[562] Doran, vol. i. p. 79.
[563] Leigh Hunt, p. 267.
[564] Cibber’s Apology, 250.
[565] Doran, vol. i. p. 466.
[566] Tatler, No. 182.
[567] Doran, vol. i. p. 464.
[568] Cumberland’s Memoirs, p. 59.
[569] Davies’s Miscellanies, vol. i. p. 126.
[570] Doran, vol. ii. p. 126.
[571] Ibid. p. 149.
[572] Doran, vol. i. p. 511.
[573] Ibid. vol. ii. p. 7.
[574] Dr. Doran, vol. ii. p. 277.
[575] Dr. Doran’s Knights and their Days.
[576] Elia, p. 217.
[577] Doran, vol. ii. p. 330.
[578] Leigh Hunt’s Essays on the Theatres, p. 124.
[579] Hazlitt’s Essays, p. 47.
[580] Elia, p. 216.
[581] Moore’s Sheridan, p. 140.
[582] Ibid. p. 181.
[583] Murphy’s Garrick.
[584] Doran, vol. ii. p. 489.
[585] Leigh Hunt’s Essays on the Theatres, p. 124.
[586] Ibid. p. 78.
[587] Hazlitt’s Criticisms of the Stage, p. 441.
[588] Elia, p. 221.
[589] Doran, vol. ii. p. 476.
[590] Hazlitt’s Essays, p. 47.
[591] Hazlitt’s Criticisms, pp. 49, 50.
[592] Elia (1853), p. 206.
[593] Elia, p. 232.
[594] Ibid. p. 213.
[595] Moore’s Life of Sheridan, p. 637.
[596] Moore’s Sheridan, p. 637.
[597] Smith’s Nollekens, vol. ii. p. 113.
[598] Hazlitt’s Essays, p. 51.
[599] Ibid. p. 212.
[600] The Georgian Era, vol. iv. p. 43.
[601] Hazlitt’s Essays, p. 49.
[602] Lounger’s Commonplace Book, vol. ii. p. 137.
[603] Dunciad, B. iii. p. 199.
[604] Lounger’s Commonplace Book, vol. ii. p. 141.
[605] The Intelligencer, No. 3.
[606] Leigh Hunt’s Town, p. 248.
[607] Fly Leaves (Miller), vol. i. p. 96.
[608] Disraeli’s Miscellanies, p. 77.
[609] Wine and Walnuts, vol. ii. p. 150.
[610] Jeaffreson’s Book about Doctors (2d ed.), p. 85.
[611] The very earliest was granted to Philip the Hermit, for
gravelling the road at Highgate.
[612] Rymer’s Fœdera.
[613] Fuller’s Church History.
[614] Vaughan’s Life of Wickliffe.
[615] Dobie’s St. Giles’s, p. 11.
[616] Ibid. (1829), p. 2.
[617] Pennant (4th ed.), p. 3.
[618] Butler’s Lives of the Saints.
[619] Aggas’s Map, published in 1578 or 1560.
[620] Stow’s Survey, 1595.
[621] Dobie’s St. Giles’s, p. 46.
[622] Evelyn’s Diary.
[623] Brayley’s Londiniana.
[624] Dobie’s St. Giles’s, pp. 58, 59.
[625] Defoe’s History of the Plague.
[626] Maitland’s History of London.
[627] Dr. Sydenham.
[628] Dr. Hodgson’s Journal of the Plague.
[629] Dr. Hodges on the Plague.
[630] Fuller’s Church History.
[631] Hume.
[632] Fuller.
[633] Parliamentary Report.
[634] Ralph.
[635] Rowland Dobie’s History of St. Giles’s, p. 119.
[636] Pennant’s London, p. 159.
[637] Cunningham’s London, vol. i. p. 339.
[638] Annual Register, 1827.
[639] Dobie’s St. Giles’s, p. 367.
[640] Strype.
[641] Strype.
[642] Dobie’s St. Giles’s, p. 225.
[643] Cunningham’s London, vol. i. p. 384.
[644] Smith’s Book for a Rainy Day, p. 21.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookball.com

You might also like