Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/342765636

Practical Data Structures C++, C#, and Java

Book · July 2020

CITATIONS READS
2 2,772

1 author:

Mohammad Ali H. Eljinini


Isra University, Jordan
33 PUBLICATIONS   199 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Education in Smart Environments View project

SOCIALmedia View project

All content following this page was uploaded by Mohammad Ali H. Eljinini on 08 July 2020.

The user has requested enhancement of the downloaded file.


M.A. Eljinini

2019

Practical
Data Structures
C++, C#, and Java

M.A. Eljinini

English
ISBN: 978-9957-67-401-4
Arabic

i
Practical Data Structures with C++, C#, and Java

Practical Data Structures


with C++, C#, and Java

Published by M.A. Eljinini


eljinini.ma@gmail.com

First Edition

Copyright © M.A. Eljinini, 2019

987654321

The author asserts the moral right to


be identified as the author of this work

ISBN: 978-9957-67-401-4

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 otherwise,
without the prior permission of the publisher.

The Hashemite Kingdom of Jordan


The Deposit Number at the National Library
(2019/12/6292)

ii
M.A. Eljinini

Content

1 CHAPTER ONE: Introduction To Data Structures........................................................... 1


1.1 Introduction .................................................................................................................... 2
1.2 Definition of Data Structures ....................................................................................... 2
1.3 Random Access Memory (RAM) ................................................................................ 4
1.4 Software ......................................................................................................................... 6
1.5 Software Development................................................................................................. 6
1.6 Case Study: Library System........................................................................................ 7
1.6.1 Understanding System Requirements ............................................................... 8
1.6.2 System Analysis .................................................................................................... 9
1.6.3 Designing the new system ................................................................................ 11
1.7 Conclusion ................................................................................................................... 13
1.8 Exercises ...................................................................................................................... 14
2 CHAPTER TWO: Introduction to C++, C#, Java ........................................................... 17
2.1 Introduction .................................................................................................................. 18
2.2 Integrated Development EnvironmentS .................................................................. 18
2.2.1 IDE for c++ and C# ............................................................................................. 19
2.2.2 IDE for java .......................................................................................................... 22
2.3 First Program ............................................................................................................... 26
2.4 Problem Solving .......................................................................................................... 30
2.5 Writing and using Methods ........................................................................................ 38
2.6 Recursive Methods ..................................................................................................... 42
2.7 Classes and Objects .................................................................................................. 46
2.8 Exercises ...................................................................................................................... 53
2.9 programming Exercises ............................................................................................. 54
3 CHAPTER THREE: Arrays Of Objects............................................................................ 57
3.1 Introduction .................................................................................................................. 58
3.2 Introduction to Arrays ................................................................................................. 58
3.3 Problem Solving with Arrays ..................................................................................... 60
3.4 Arrays of Objects ........................................................................................................ 66

iii
Practical Data Structures with C++, C#, and Java

3.5 The application of borrowing books ......................................................................... 70


3.6 Hash Tables................................................................................................................. 76
3.7 Exercises ...................................................................................................................... 78
3.8 Programming Exercises............................................................................................. 80
4 CHAPTER FOUR: Linked Lists ........................................................................................ 81
4.1 Introduction .................................................................................................................. 82
4.2 Introduction to Linked lists ......................................................................................... 82
4.2.1 Printing linked lists .............................................................................................. 86
4.2.2 Searching Nodes in linked lists ......................................................................... 87
4.2.3 Delete a node from the linked list ..................................................................... 88
4.3 Circular Doubly Linked lists ....................................................................................... 89
4.3.1 Printing data in circular doubly linked list ........................................................ 93
4.3.2 Searching a doubly linked list ........................................................................... 93
4.3.3 Delete node from circular doubly linked list .................................................... 94
4.4 Problem Solving with Linked Lists............................................................................ 95
4.5 Linked Lists of Objects ............................................................................................. 101
4.6 Updating the Books Borrowing Application........................................................... 103
4.7 Exercises .................................................................................................................... 109
4.8 programming Exercises ........................................................................................... 111
5 CHAPTER FIVE: Stacks .................................................................................................. 113
5.1 Introduction ................................................................................................................ 114
5.2 Introduction to Stacks............................................................................................... 114
5.3 Example: Decimal To Binary ................................................................................... 115
5.4 Array-based Stacks .................................................................................................. 116
5.5 Linked-Based Stacks................................................................................................ 117
5.6 Stacks Applications .................................................................................................. 119
5.6.1 Balancing Parentheses .................................................................................... 119
5.6.2 Math Expressions ............................................................................................. 120
5.6.3 Postfix Evaluation ............................................................................................. 123
5.7 Application of Stack in Recursive Methods........................................................... 123
5.8 Exercises .................................................................................................................... 124
5.9 programming Exercises ........................................................................................... 125
6 CHAPTER SIX: Queues .................................................................................................. 127

iv
M.A. Eljinini

6.1 Introduction ................................................................................................................ 128


6.1 Introduction to Queues............................................................................................. 128
6.2 Circular Queue .......................................................................................................... 129
6.3 Array-based Queues ................................................................................................ 130
6.4 Linked-Based Queues.............................................................................................. 131
6.5 Queues Applications ................................................................................................ 133
6.5.1 Queues in Operating Systems ........................................................................ 133
6.5.2 Queues in Simulation Experiments ................................................................ 134
6.5.3 Application of Palindromes .............................................................................. 134
6.6 Exercises .................................................................................................................... 135
6.7 programming Exercises ........................................................................................... 137
7 CHAPTER SEVEN: Trees ............................................................................................... 139
7.1 Introduction ................................................................................................................ 140
7.2 Introduction to Trees ................................................................................................ 140
7.3 Binary Trees .............................................................................................................. 141
7.4 Array-Based Trees.................................................................................................... 142
7.5 Linked-Based Trees ................................................................................................. 144
7.6 Applications of Binary trees: Heap ......................................................................... 149
7.6.1 Priority Queue.................................................................................................... 149
7.6.2 Heap Sort ........................................................................................................... 150
7.7 Traversing Trees ....................................................................................................... 151
7.8 Binary Search Tree (BST) ....................................................................................... 154
7.8.1 Searching in a BST........................................................................................... 154
7.8.2 An application of BST: TreeSort ..................................................................... 156
7.9 AVL Trees .................................................................................................................. 157
7.10 B-Trees ....................................................................................................................... 162
7.11 Hoffman Codes ......................................................................................................... 163
7.12 Exercises .................................................................................................................... 167
7.13 programming Exercises ........................................................................................... 169
8 CHAPTER EIGHT: Graphs ............................................................................................. 171
8.1 Introduction ................................................................................................................ 172
8.2 Graph theory .............................................................................................................. 172
8.3 size of graph .............................................................................................................. 173

v
Practical Data Structures with C++, C#, and Java

8.3.1 degree of vertex ................................................................................................ 173


8.3.2 path ..................................................................................................................... 173
8.3.3 Circle ................................................................................................................... 174
8.4 Types of Graphs ....................................................................................................... 174
8.4.1 Directed Graphs ................................................................................................ 174
8.4.2 Undirected Graphs............................................................................................ 174
8.5 Graphs Representation ............................................................................................ 175
8.5.1 Adjacency Matrix............................................................................................... 175
8.5.2 Linked Adjacency List ...................................................................................... 177
8.6 Applications of Graphs ............................................................................................. 180
8.7 Graph Searching ....................................................................................................... 181
8.8 Exercises .................................................................................................................... 186
8.9 programming Exercises ........................................................................................... 188

vi
M.A. Eljinini

Preface

Computer Scientists have developed many programming languages, from assembly language in
the 40s, FORTRAN and COBOL in the 50s, BASIC and PL/I in the 60s, C and Prolog in the 70s,
among many other programming languages, like the ones to process and manage databases. The
80s have brought more advances, notably object-oriented programming languages like C++ and
Objective-C. In the 90s, the development of programming languages was influenced heavily by
the Internet revolution. Some of the most notable programming languages were Visual Basic, Java,
JavaScript, and PHP. The evolution of programming languages continued in the twenty and
twenty-one century with increasing trends toward security and reliability verification, concurrency
and massive parallelism, distribution and mobility, graphical interfaces, more integration with
databases including XML and relational databases. One of the most notable programming
languages of the modern era is C-Sharp (C#). C# is becoming very popular among programmers
for its productive environment, which is called the .NET Framework. The .NET Framework consists
of ready to use classes that are well written and well documented. They are handy for beginner
and professional programmers alike.
Computers are made to process all sorts of data. Writing good software is an art that involves
many steps. One of these steps is the design and implementation of data structures.
This book comes to achieve this goal; to design and implement data structures that we can use in
applications. The approach used in this book is very practical. Real-life applications have been
explained and developed gradually from scratch with an emphasis on the different types of data
structures. This book comes full of figures and examples that aid the student in understanding the
concepts of data structures. It contains many MC exercises and programming exercises that are
useful for students to help them master the topics. It is the first data structures book that is written
in both English and Arabic languages, side-by-side. It is the first data structures book that presents
examples in three programming languages, C++, C#, and Java. It is a unique, multi-language book
by all meanings.
The first chapter consists of several sections aimed at identifying basic concepts of ICT in terms of
hardware and software. It also addresses the basic fundaments of data structures. As well as the
mechanism of problem solving and software development, accompanied by a real-life case study.
The second chapter provides a brief tutorial of the main concepts and structures of the C++, C#,
and Java programming languages that we use throughout this book. It starts by pointing out the
advantages of using these programming languages. It has a section devoted to each language.
We introduce each one of the three programming languages, and we present their traits and
peculiarities. The best development tools for each language has been discussed and then shown
how to download them, install them, and use them. Finally, we present a comparison of the three
programming languages via some examples, which we show in detail. This section does not cover
the three programming languages in detail; instead, it covers the necessary material needed for
the rest of the chapters.
The third chapter presents arrays in general and arrays of objects in particular. Arrays of objects
are one of the building blocks in data structures. It is crucial to understand this subject before
moving any farther. The chapter ends with covering step-by-step the utilization of the arrays of
objects in the real-life case study. The fourth chapter presents linked lists, which are the other

vii
Practical Data Structures with C++, C#, and Java

building block in data structures. It presents the primary operations performed on linked lists, such
as adding and deleting objects in linked lists, searching, and printing the content of these objects.
It covers other types of linked lists, such as circular and doubly-linked lists. At the end of the chapter,
it shows how to switch from arrays to linked lists in detail via the case study. In the fifth chapter to
the eighth chapter, we present and cover the various types of data structures, namely stacks,
queues, trees, and graphs in detail. These are the primary data structures that make up most of
this book. Each chapter provides definitions and examples to advance the understanding of each
of these data structures. Also, the implementations of these structures using arrays and linked lists
are presented and worked out. Finally, many examples demonstrate how these data structures are
used in real-life applications.

Mohammad Ali Eljinini, Ph.D.

Associate Professor

Faculty of Information Technology

Isra University, Amman - Jordan

viii
M.A. Eljinini

1. CHAPTER ONE: INTRODUCTION TO DATA STRUCTURES

Objectives of Chapter 1 ‫ﺃﻫﺩﺍﻑ ﺍﻟﻭﺣﺩﺓ ﺍﻷﻭﻟﻰ‬


1. Understand the fundamentals of Data ‫ﻓﻬﻡ ﺍﻟﻣﺑﺎﺩﺉ ﺍﻻﺳﺎﺳﻳﺔ ﻓﻲ ﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ‬ .1
Structures (RAM) ‫ﻓﻬﻡ ﺩﻭﺭ ﺫﺍﻛﺭﺓ ﺍﻟﻭﺻﻭﻝ ﺍﻟﻌﺷﻭﺍﺋﻲ‬ .2
2. Understand the role of Random-Access ‫ﺗﻌﺭﻑ ﻋﻠﻰ ﺩﻭﺭﺓ ﺗﻁﻭﻳﺭ ﺍﻟﺑﺭﻣﺟﻳﺎﺕ ﻭﺩﻭﺭ‬ .3
Memory (RAM) ‫ﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ‬
3. Learn about the Software Development Cycle ‫ﺗﻁﺑﻳﻖ ﺧﻁﻭﺍﺕ ﺣﻝ ﺍﻟﻣﺷﻛﻼﺕ ﺑﺎﺳﺗﺧﺩﺍﻡ‬ .4
and the role of data structures ‫ﺩﺭﺍﺳﺔ ﺗﺣﻠﻳﻠﻳﺔ ﻟﻣﺛﺎﻝ ﻭﺍﻗﻌﻲ‬
4. Applying the problem-solving steps using a
Case Study

1
‫‪Practical Data Structures with C++, C#, and Java‬‬

‫‪1.1‬‬ ‫‪INTRODUCTION‬‬

‫‪This chapter aims to present the fundament‬‬ ‫ﺗﻬﺩﻑ ﺍﻟﻭﺣﺩﺓ ﺍﻻﻭﻟﻰ ﺇﻟﻰ ﺍﻟﺗﻌﺭﻑ ﻋﻠﻰ ﺍﻟﻣﻔﺎﻫﻳﻡ ﺍﻷﺳﺎﺳﻳﺔ ﻓﻲ ﻫﻳﺎﻛﻝ‬
‫‪concepts of data structures, its types, and‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﻋﻠﻰ ﺃﻧﻭﺍﻋﻬﺎ ﻭﺍﺳﺗﺧﺩﺍﻣﺎﺗﻬﺎ ﻓﻲ ﺗﻛﻧﻭﻟﻭﺟﻳﺎ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ‪ .‬ﻫﺫﻩ‬
‫‪usages in the field of Information Technology.‬‬ ‫ﺍﻟﻭﺣﺩﺓ ﺳﺗﻛﻭﻥ ﺗﻣﻬﻳﺩﺍ ﺇﻟﻰ ﺑﺎﻗﻲ ﺍﻟﻭﺣﺩﺍﺕ ﻛﻣﺎ ﺳﺗﻛﻭﻥ ﻣﺩﻋﻣﺔ ﺑﺎﻷﻣﺛﻠﺔ‬
‫‪First, we give a brief description of the rest of the‬‬ ‫ﺍﻟﻭﺍﻗﻌﻳﺔ ﻭﺍﻟﺗﻲ ﺳﺗﻌﺯﺯ ﻣﻥ ﺗﻭﺿﻳﺢ ﺍﻟﻣﻔﺎﻫﻳﻡ ﺍﻷﺳﺎﺳﻳﺔ ﻓﻲ ﺗﻁﻭﻳﺭ‬
‫‪chapters of this book. We then present some‬‬ ‫ﺍﻟﺑﺭﻣﺟﻳﺎﺕ ﺑﺷﻛﻝ ﻋﺎﻡ ﻭﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ ﺑﺷﻛﻝ ﺧﺎﺹ‪.‬‬
‫‪examples that explain the main concepts of‬‬ ‫ﻓﻲ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺛﺎﻧﻳﺔ ﺳﻳﺗﻡ ﻋﺭﺽ ﻣﻘﺩﻣﺔ ﻓﻲ ﻟﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ ﺍﻟﺳﻲ ‪، ++‬‬
‫‪software production in general and data‬‬ ‫ﻭﺍﻟﺳﻲ ‪ ، #‬ﻭﺍﻟﺟﺎﻓﺎ ﻭﺍﻟﺗﻲ ﺳﻧﺳﺗﺧﺩﻣﻬﺎ ﺧﻼﻝ ﺷﺭﺣﻧﺎ ﻟﻣﺎﺩﺓ ﻫﻳﺎﻛﻝ‬
‫‪structures in specific.‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ‪ .‬ﺗﻡ ﺍﺧﺗﻳﺎﺭ ﻫﺫﻩ ﺍﻟﻠﻐﺎﺕ ﺍﻟﺛﻼﺛﺔ ﻟﻠﻌﺩﻳﺩ ﻣﻥ ﺍﻷﺳﺑﺎﺏ‪ ،‬ﻓﻬﻲ‬
‫‪C-Plus-Plus (C++), C-Sharp (C#), and Java are‬‬ ‫ﺟﻣﻳﻌﻬﺎ ﻟﻐﺎﺕ ﻛﺎﺋﻧﻳﺔ ﺍﻟﻣﻧﺣﻰ ﺃﻱ ﺃﻧﻬﺎ ﺗﻌﺗﻣﺩ ﻋﻠﻰ ﺗﺻﻧﻳﻑ ﺍﻷﺷﻳﺎء ﻓﻲ‬
‫‪the languages that we use throughout this book‬‬ ‫ﻛﺗﺎﺑﺔ ﺍﻟﺑﺭﺍﻣﺞ ﻭﺍﻟﺗﻲ ﺗﻛﻭﻥ ﺃﻗﺭﺏ ﺇﻟﻰ ﺍﻟﻭﺍﻗﻊ‪ .‬ﻭﻣﻥ ﻓﻭﺍﺋﺩ ﻫﺫﻩ ﺍﻟﻠﻐﺎﺕ‬
‫‪to explain the subject of data structures. All three‬‬ ‫ﺃﻧﻬﺎ ﻣﺗﻌﺩﺩﺓ ﺍﻟﻣﻧﺻﺎﺕ ﺃﻱ ﺃﻥ ﺍﻟﺑﺭﺍﻣﺞ ﺍﻟﺗﻲ ﺗﻛﺗﺏ ﻳﻣﻛﻥ ﺗﻧﻔﻳﺫﻫﺎ ﻋﻠﻰ ﺃﻱ‬
‫‪computer languages are used in the teaching of‬‬ ‫ﻧﻅﺎﻡ ﻛﻭﻳﻧﺩﻭﺯ ﺃﻭ ﻟﻳﻧﻛﺱ ﺃﻭ ﻏﻳﺭﻫﺎ ﺩﻭﻥ ﺍﻟﺣﺎﺟﺔ ﺇﻟﻰ ﺇﻋﺎﺩﺓ ﻛﺗﺎﺑﺗﻬﺎ‪ .‬ﺇﻥ‬
‫‪computer programming in many universities‬‬ ‫ﻏﺎﻟﺑﻳﺔ ﻛﻠﻳﺎﺕ ﺗﻛﻧﻭﻟﻭﺟﻳﺎ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻓﻲ ﺍﻟﺟﺎﻣﻌﺎﺕ‪ ،‬ﻣﺣﻠﻳﺎ ﻭﻋﺭﺑﻳﺎ ﻭﺣﺗﻰ‬
‫‪around the world.‬‬ ‫ﻋﺎﻟﻣﻳﺎ ﺗﻌﺗﻣﺩ ﻟﻐﺔ ﺃﻭ ﺃﻛﺛﺭ ﻣﻥ ﻫﺫﻩ ﺍﻟﻠﻐﺎﺕ ﺍﻟﺛﻼﺛﺔ ﻛﻣﺎﺩﺓ ﺃﺳﺎﺳﻳﺔ ﻣﺳﺗﺧﺩﻣﺔ‬
‫‪In chapter 2, we provide a tutorial of the main‬‬ ‫ﻓﻲ ﺗﻌﻠﻡ ﺍﻟﺑﺭﻣﺟﺔ ﻭﻓﻲ ﻋﻣﻝ ﺍﻟﺗﻁﺑﻳﻘﺎﺕ ﻟﻣﻭﺍﺩ ﺍﻟﺣﺎﺳﻭﺏ ﺍﻷﺧﺭﻯ‪،‬‬
‫‪concepts and structures of these programming‬‬ ‫ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺍﺳﺗﺧﺩﺍﻣﺎﺗﻬﺎ ﺍﻟﺷﺎﺋﻌﺔ ﻓﻲ ﺃﺳﻭﺍﻕ ﺍﻟﻌﻣﻝ ﺍﻟﻣﺣﻠﻳﺔ ﻭﺍﻟﻌﺎﻟﻣﻳﺔ‪.‬‬
‫‪languages. In chapter 3, we present arrays in‬‬ ‫ﻭﻣﻥ ﻓﻭﺍﺋﺩ ﻫﺫﻩ ﺍﻟﻠﻐﺎﺕ ﺃﻧﻪ ﻳﻣﻛﻥ ﺭﺑﻁ ﺍﻟﺑﺭﺍﻣﺞ ﺍﻟﺗﻲ ﻧﻁﻭﺭﻫﺎ ﻣﻊ ﺃﻧﻅﻣﺔ‬
‫‪general and arrays of objects in particular.‬‬ ‫ﻗﻭﺍﻋﺩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻣﺛﻝ ﻣﺎﻳﻛﺭﻭﺳﻭﻓﺕ ﺃﻛﺳﺱ ﻭﺃﻭﺭﺍﻛﻝ ﻭﻣﺎﻱ‪-‬ﺇﺱ‪-‬ﻛﻳﻭ‪-‬ﺇﻝ‬
‫‪Arrays of objects are one of the building blocks‬‬ ‫ﻭﻏﻳﺭﻫﺎ‪ .‬ﻭﻫﻧﺎ ﻳﺟﺩﺭ ﺍﻹﺷﺎﺭﺓ ﺇﻟﻰ ﺍﻧﻪ ﻳﻣﻛﻥ ﺍﻟﺣﺻﻭﻝ ﻋﻠﻳﻬﺎ ﺟﻣﻳﻌﺎ ﻣﺟﺎﻧﺎ‬
‫‪in data structures. It is very important to‬‬ ‫ﺩﻭﻥ ﺍﻟﺣﺎﺟﺔ ﺇﻟﻰ ﺩﻓﻊ ﺃﻱ ﻣﺑﻠﻎ ﻣﻥ ﺍﻟﻣﺎﻝ ﻻﺳﺗﺧﺩﺍﻣﻬﺎ‪ .‬ﻓﻔﻲ ﻫﺫﺍ ﺍﻟﻛﺗﺎﺏ‬
‫‪understand this subject before moving any‬‬ ‫ﺗﻡ ﺍﻋﺗﻣﺎﺩ ﺗﻁﺑﻳﻖ ﻓﻳﺟﻭﺍﻝ ﺳﺗﻭﺩﻳﻭ ﻟﺗﻁﻭﻳﺭ ﺑﺭﺍﻣﺞ ﺳﻲ‪ ++‬ﻭﺳﻲ‪ ،#‬ﺣﻳﺙ‬
‫‪farther. In chapter 4, we present linked lists,‬‬ ‫ﻳﻣﻛﻥ ﺍﻟﺣﺻﻭﻝ ﻋﻠﻰ ﻧﺳﺧﺔ ﺍﻛﺳﺑﺭﻳﺱ ﺃﻭ ﻛﻭﻣﻳﻭ ﻧﻳﺗﻲ ﻋﻥ ﻁﺭﻳﻖ ﻣﻭﻗﻊ‬
‫‪which are another building block in data‬‬ ‫ﻣﺎﻳﻛﺭﻭﺳﻭﻓﺕ ﻣﺟﺎﻧﺎ‪ .‬ﻛﻣﺎ ﻳﻭﺟﺩ ﻋﺩﺩ ﻛﺑﻳﺭ ﻣﻥ ﺍﻟﻣﺻﺎﺩﺭ ﻭﺍﻟﻣﺭﺍﺟﻊ‬
‫‪structures. In chapter 5 to chapter 8, we present‬‬ ‫ﻋﻠﻰ ﺍﻟﺷﺑﻛﺔ ﺍﻟﻌﻧﻛﺑﻭﺗﻳﺔ ﻭﺍﻟﻣﺗﺧﺻﺻﺔ ﻟﻬﺫﻩ ﺍﻟﻠﻐﺎﺕ ﻭﺍﻟﺗﻲ ﻳﻣﻛﻥ ﺍﻟﺭﺟﻭﻉ‬
‫‪Stacks,‬‬ ‫‪Queues,‬‬ ‫‪Trees,‬‬ ‫‪and‬‬ ‫‪Graphs‬‬ ‫ﺇﻟﻳﻬﺎ ﻟﻠﺣﺻﻭﻝ ﻋﻠﻰ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻭﺍﻟﻣﻭﺍﺩ ﺍﻟﺗﻌﻠﻳﻣﻳﺔ ﻭﺍﻟﺗﻲ ﺗﻧﺎﺳﺏ ﺟﻣﻳﻊ‬
‫‪respectively. These are the main data structures‬‬ ‫ﺍﻟﻣﺳﺗﻭﻳﺎﺕ‪ .‬ﺗﺗﺿﻣﻥ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺛﺎﻧﻳﺔ ﺍﻷﺳﺎﺳﻳﺎﺕ ﻓﻲ ﻟﻐﺎﺕ ﺍﻟﺳﻲ‪++‬‬
‫‪that make up most of this book. We provide a‬‬ ‫ﻭﺍﻟﺳﻲ‪ #‬ﻭﺍﻟﺟﺎﻓﺎ‪ ،‬ﻭﺳﺗﻛﻭﻥ ﻫﺫﻩ ﺍﻟﻭﺣﺩﺓ ﻣﻘﺩﻣﺔ ﻟﻠﻭﺣﺩﺓ ﺍﻟﺛﺎﻟﺛﺔ ﻭﺍﻟﺗﻲ‬
‫‪definition of each one of them, and then we give‬‬ ‫ﺳﻧﺳﺗﻌﺭﺽ ﻓﻳﻬﺎ ﻣﻭﺿﻭﻉ ﺍﻟﻣﺻﻔﻭﻓﺎﺕ ﺑﺷﻛﻝ ﻋﺎﻡ ﻭﺍﻟﻣﺻﻔﻭﻓﺎﺕ ﻣﻥ‬
‫‪some examples to advance our understanding of‬‬ ‫ﺍﻟﻛﺎﺋﻧﺎﺕ ﺑﺷﻛﻝ ﺧﺎﺹ‪ .‬ﺗﻌﺗﺑﺭ ﺍﻟﻣﺻﻔﻭﻓﺎﺕ ﺍﻟﻣﻛﻭﻧﺔ ﻣﻥ ﺍﻟﻛﺎﺋﻧﺎﺕ‬
‫‪each of these data structure. We show how we‬‬ ‫ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺍﻟﻘﻭﺍﺋﻡ ﺍﻟﻣﺗﺭﺍﺑﻁﺔ ﺇﺣﺩﻯ ﺍﻟﻠﺑﻧﺎﺕ ﺍﻻﺳﺎﺳﻳﺔ ﻓﻲ ﻣﺎﺩﺓ ﻫﻳﺎﻛﻝ‬
‫‪use them in our programs; first, we implement‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﺍﻟﺗﻲ ﺳﻳﺗﻡ ﺍﻟﺗﺭﻛﻳﺯ ﻋﻠﻳﻬﺎ ﻓﻲ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺭﺍﺑﻌﺔ‪ .‬ﺃﻣﺎ ﺍﻟﻭﺣﺩﺍﺕ‬
‫‪these data structures using arrays and then‬‬ ‫ﺍﻟﺧﺎﻣﺳﺔ ﺇﻟﻰ ﺍﻟﺛﺎﻣﻧﺔ ﻓﺳﻧﺳﺗﻌﺭﺽ ﻓﻳﻬﺎ ﺍﻟﻣﻛﺩﺳﺎﺕ ﻭﺍﻟﻁﻭﺍﺑﻳﺭ ﻭﺍﻻﺷﺟﺎﺭ‬
‫‪linked lists. Finally, we provide more real-life‬‬ ‫ﻭﺍﻟﻣﺧﻁﻁﺎﺕ ﻋﻠﻰ ﺍﻟﺗﻭﺍﻟﻲ‪ .‬ﺗﺑﺩﺃ ﻛﻝ ﻭﺣﺩﺓ ﺑﺎﻟﺗﻌﺭﻳﻑ ﻋﻥ ﻫﻳﻛﻠﺔ ﺍﻟﺑﻳﺎﻧﺎﺕ‬
‫‪examples and show how these data structures‬‬ ‫ﻭﻣﻥ ﺛﻡ ﻋﺭﺽ ﺃﻣﺛﻠﺔ ﺑﺳﻳﻁﺔ‪ ،‬ﺛﻡ ﻧﻌﺭﺽ ﻛﻳﻔﻳﺔ ﺑﺭﻣﺟﺔ ﻛﻝ ﻣﻥ ﻫﻳﺎﻛﻝ‬
‫‪are used in real-life applications.‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﺑﺎﺳﺗﺧﺩﺍﻡ ﺍﻟﻣﺻﻔﻭﻓﺎﺕ ﺃﻭﻻ ﻭﻣﻥ ﺛﻡ ﺑﺎﺳﺗﺧﺩﺍﻡ ﺍﻟﻘﻭﺍﺋﻡ ﺍﻟﻣﺗﺭﺍﺑﻁﺔ‬
‫ﻭﺑﻠﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ ﺍﻟﺛﻼﺛﺔ‪ .‬ﻓﻲ ﻧﻬﺎﻳﺔ ﻛﻝ ﻭﺣﺩﺓ ﻧﻌﺭﺽ ﺃﻣﺛﻠﺔ ﻭﺍﻗﻌﻳﺔ‬
‫ﻭﺗﻁﺑﻳﻘﺎﺕ ﻋﺩﻳﺩﺓ‪.‬‬

‫‪1.2‬‬ ‫‪DEFINITION OF DATA STRUCTURES‬‬

‫‪Data Structures is about organizing, managing, and storing our‬‬ ‫ﺇﻥ ﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ ﺗﻌﻧﻰ ﺑﺗﻧﻅﻳﻡ ﻭﺇﺩﺍﺭﺓ ﻭﻫﻳﻛﻠﺔ‬
‫‪data efficiently. Our programs usually reserve space for our data‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ‪ ،‬ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ‬
‫‪in the main memory of the computer. The Main Memory is also‬‬ ‫ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﺗﻲ ﺗﻘﻭﻡ ﻋﻠﻳﻬﺎ‪ ،‬ﻭﺫﻟﻙ ﺑﻘﺻﺩ‬
‫‪called Radom Access Memory (RAM). Data structures is about‬‬ ‫ﺍﺳﺗﺧﺩﺍﻣﻬﺎ ﺑﺷﻛﻝ ﻓﺎﻋﻝ ﺟﺩﺍ‪ .‬ﻣﻥ ﺍﻟﻌﻠﻣﻳﺎﺕ ﺍﻟﺗﻲ‬
‫‪structuring and processing our data, which we will use in our‬‬ ‫ﻳﺗﻡ ﺗﻧﻔﻳﺫﻫﺎ ﻋﻠﻰ ﺍﻟﺑﻳﺎﻧﺎﺕ ﺍﻟﺣﻔﻅ‪ ،‬ﻭﺍﻻﺳﺗﺭﺟﺎﻉ‪،‬‬
‫‪programs in very efficient ways. We will learn how to store and‬‬ ‫ﻭﺍﻟﺗﻌﺩﻳﻝ‪ ،‬ﻭﺍﻟﺑﺣﺙ‪ .‬ﻓﻌﻧﺩﻣﺎ ﻧﻧﻔﺫ ﺃﻱ ﺑﺭﻧﺎﻣﺞ ﻓﺈﻧﻪ‬
‫‪retrieve our data, how to update it, and even how to search for‬‬ ‫ﻳﻘﻭﻡ ﺑﺣﺟﺯ ﺟﺯء ﻣﻥ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
‫‪items. Figure 1-1 shows the main reason for using computers,‬‬ ‫ﻟﻠﺑﻳﺎﻧﺎﺕ ﺍﻟﺗﻲ ﻳﻌﺎﻟﺟﻬﺎ‪ .‬ﺍﻟﺷﻛﻝ ‪ 1-1‬ﻳﻌﺭﺽ‬
‫‪which is to process our data into useful information. Our data may‬‬ ‫ﺍﻟﻬﺩﻑ ﺍﻟﺭﺋﻳﺳﻲ ﻣﻥ ﺍﻟﺣﺎﺳﻭﺏ ﻭﻫﻭ ﻣﻌﺎﻟﺟﺔ‬
‫‪take several forms like numbers, characters, words, text, and‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ‪ .‬ﺇﻥ ﻫﺫﻩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻗﺩ ﺗﺄﺧﺫ ﺃﺷﻛﺎﻻ ﻣﺧﺗﻠﻔﺔ‬
‫‪even images and sounds.‬‬

‫‪2‬‬
M.A. Eljinini

‫ﻣﻥ ﺃﻋﺩﺍﺩ ﻭﺃﺣﺭﻑ ﻭﻛﻠﻣﺎﺕ ﻭﺟﻣﻝ ﻭﺣﺗﻰ ﺻﻭﺭ‬


.‫ﻭﺃﺻﻭﺍﺕ‬

INPUT PROCESS OUTPUT


Data Data Data
Figure 1-1: Data Processing
How do we input our data into the computer? Where do we
‫ﺃﻱ ﺃﻥ ﻫﺫﻩ ﺍﻷﻋﺩﺍﺩ ﻭﺍﻟﺣﺭﻭﻑ ﻭﺍﻟﺻﻭﺭ ﺗﺩﺧﻝ ﻋﻠﻰ‬
save this data? Moreover, how does the computer processes
it into useful information? Data may enter the computer via ‫ﺷﻛﻝ ﺑﻳﺎﻧﺎﺕ ﻭﻳﺗﻡ ﻣﻌﺎﻟﺟﺗﻬﺎ ﻓﻲ ﺍﻟﺣﺎﺳﻭﺏ ﺛﻡ ﺗﺧﺭﺝ‬
its keyboard or come from the Internet or may even enter ‫ ﻭﻟﻛﻥ ﻛﻳﻑ ﻳﺗﻡ ﺇﺩﺧﺎﻝ‬.‫ﻋﻠﻰ ﺷﻛﻝ ﻣﻌﻠﻭﻣﺎﺕ ﻣﻔﻳﺩﺓ‬
from the camera like pictures. We may use special programs ‫ﺍﻟﺑﻳﺎﻧﺎﺕ؟ ﻭﺃﻳﻥ ﻳﺗﻡ ﺗﺧﺯﻳﻧﻬﺎ؟ ﻭﻛﻳﻑ ﻳﺗﻡ ﻣﻌﺎﻟﺟﺗﻬﺎ ﻓﻲ‬
like Adobe Photoshop to process it, and then save these ‫ﺩﺍﺧﻝ ﺍﻟﺣﺎﺳﻭﺏ؟ ﻭﻟﻺﺟﺎﺑﺔ ﻋﻥ ﻫﺫﻩ ﺍﻻﺳﺋﻠﺔ ﻓﺎﻟﺑﻳﺎﻧﺎﺕ‬
pictures to the hard disk or send it to someone on the ‫ﻗﺩ ﺗﺩﺧﻝ ﻋﻥ ﻁﺭﻳﻖ ﻭﺣﺩﺓ ﺍﻟﻣﻔﺎﺗﻳﺢ ﺃﻭ ﻋﻥ ﻁﺭﻳﻖ‬
Internet. We may use the calculator to enter numbers, ‫ﺷﺑﻛﺔ ﺍﻟﺣﺎﺳﻭﺏ ﻛﺎﻹﻧﺗﺭﻧﺕ ﺃﻭ ﻋﻥ ﻁﺭﻳﻖ ﺍﻟﻛﺎﻣﻳﺭﺍ‬
perform calculations, and display results. We may use MS
‫ﺍﻟﺭﻗﻣﻳﺔ ﻛﺎﻟﺻﻭﺭ ﺑﺎﺳﺗﺧﺩﺍﻡ ﺑﺭﺍﻣﺞ ﻣﻌﻳﻧﺔ ﻭﺍﻟﺗﻲ ﺗﻌﻣﻝ‬
Word to type text, process it into something more beautiful,
and then send it to the printer or save it on the hard disk. We ‫ﻋﻠﻰ ﺇﺩﺧﺎﻝ ﻫﺫﻩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﺣﻔﻅﻬﺎ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ‬
may write our programs using C++ or Java to enter data, ‫ ﻓﻣﺛﻼ ﻧﺳﺗﺧﺩﻡ ﺑﺭﻧﺎﻣﺞ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ‬.‫ﻭﻣﻥ ﺛﻡ ﻣﻌﺎﻟﺟﺗﻬﺎ‬
process it, and then output it into something more useful. ‫ﻹﺩﺧﺎﻝ ﺍﻷﻋﺩﺍﺩ ﻭﺍﻟﻘﻳﺎﻡ ﺑﺎﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﺣﺳﺎﺑﻳﺔ ﻋﻠﻳﻬﺎ‬
The two main things we load into the computer memory ‫ ﻭﻧﺳﺗﺧﺩﻡ ﺑﺭﻧﺎﻣﺞ ﻣﺎﻳﻛﺭﻭﺳﻭﻓﺕ‬.‫ﻭﺇﺧﺭﺍﺝ ﺍﻟﻧﺗﺎﺋﺞ‬
(RAM) are the data and the programs. Programs are the ‫ﻭﻭﺭﺩ ﻹﺩﺧﺎﻝ ﺍﻟﻧﺻﻭﺹ ﻭﻣﻌﺎﻟﺟﺗﻬﺎ ﻭﺗﻧﺳﻳﻘﻬﺎ‬
codes that process the data. Each entity has its own space ‫ ﻭﻧﺳﺗﺧﺩﻡ ﺑﺭﻧﺎﻣﺞ‬.‫ﻭﺣﻔﻅﻬﺎ ﺃﻭ ﻁﺑﺎﻋﺗﻬﺎ ﻋﻠﻰ ﺍﻟﻭﺭﻕ‬
in memory. A third entity is an operating system (OS) like
‫ﺃﺩﻭﺑﻲ ﻓﻭﺗﻭﺷﻭﺏ ﻹﺩﺧﺎﻝ ﺍﻟﺻﻭﺭ ﻋﻥ ﻁﺭﻳﻖ ﺍﻟﻛﺎﻣﻳﺭﺍ‬
MS Windows. Figure 1-2 shows how the main memory
(RAM) looks like in general. ‫ﻭﻋﻣﻝ ﺍﻟﺗﻌﺩﻳﻝ ﻋﻠﻳﻬﺎ ﻭﺣﻔﻅﻬﺎ ﻋﻠﻰ ﺍﻟﻘﺭﺹ ﺍﻟﺻﻠﺏ‬
‫ ﻭﻗﺩ ﻧﻁﻭﺭ ﺑﺭﺍﻣﺟﻧﺎ‬.‫ﺃﻭ ﺇﺭﺳﺎﻟﻬﺎ ﻋﻥ ﻁﺭﻳﻖ ﺍﻹﻧﺗﺭﻧﺕ‬
‫ﺍﻟﺧﺎﺻﺔ ﺑﺎﺳﺗﺧﺩﺍﻡ ﺇﺣﺩﻯ ﻟﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ ﻛﺎﻟﺳﻲ ﺷﺎﺭﺏ‬
OS Kernel Space ‫ﺃﻭ ﺍﻟﺟﺎﻓﺎ ﻣﺛﻼ ﻹﺩﺧﺎﻝ ﺑﻳﺎﻧﺎﺕ ﻣﻌﻳﻧﺔ ﻭﻣﻌﺎﻟﺟﺗﻬﺎ ﺣﺳﺏ‬
‫ ﻣﻥ ﻫﻧﺎ‬.‫ﺍﻟﻣﻁﻠﻭﺏ ﻣﻧﻬﺎ ﻭﺇﺧﺭﺍﺟﻬﺎ ﺑﺎﻟﻁﺭﻳﻘﺔ ﺍﻟﻣﻧﺎﺳﺑﺔ‬
‫ﻳﺟﺏ ﺍﻻﻧﺗﺑﺎﻩ ﺇﻟﻰ ﺃﻥ ﻫﻧﺎﻟﻙ ﻧﻭﻋﺎﻥ ﻣﻥ ﺍﻟﻌﻧﺎﺻﺭ ﺍﻟﺗﻲ‬
Code Segment ‫ ﻓﻬﻧﺎﻟﻙ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﻫﻧﺎﻟﻙ‬،‫ﺗﺣﻔﻅ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ‬
‫ﺍﻟﺑﺭﺍﻣﺞ ﺍﻟﺗﻲ ﺗﻌﺎﻟﺞ ﻫﺫﻩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﻛﻼﻫﻣﺎ ﻳﺄﺧﺫ ﺣﻳﺯﺍ‬
‫ ﻫﺫﺍ‬.‫ﻣﻧﻔﺻﻼ ﻓﻲ ﺍﻟﺫﺍﻛﺭﺓ ﺍﻟﻌﺷﻭﺍﺋﻳﺔ ﻟﻠﺣﺎﺳﻭﺏ‬
‫ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺍﻟﺟﺯء ﺍﻟﻣﺧﺻﺹ ﻟﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﻣﺛﻝ‬
Data Segment .2-1 ‫ ﻭﻛﻣﺎ ﻣﺑﻳﻥ ﻓﻲ ﺍﻟﺷﻛﻝ‬،‫ﻧﻅﺎﻡ ﻭﻳﻧﺩﻭﺯ ﺃﻭ ﻟﻳﻧﻛﺱ‬

Figure 1-2: The Main Parts of RAM

When we turn on our computer, a small computer program


‫ﻓﻲ ﺍﻟﺑﺩﺍﻳﺔ ﻋﻧﺩﻣﺎ ﻧﻘﻭﻡ ﺑﺎﻟﺿﻐﻁ ﻋﻠﻰ ﺯﺭ ﺍﻟﺗﺷﻐﻳﻝ‬
called (Boot Loader) that lives in a Read-Only Memory (ROM)
‫ﻓﻲ ﺟﻬﺎﺯ ﺍﻟﺣﺎﺳﻭﺏ ﻳﻘﻭﻡ ﺑﺭﻧﺎﻣﺞ ﺣﺎﺳﻭﺑﻲ ﺻﻐﻳﺭ‬
runs and starts working. This program’s job is to ensure the
‫ﻳﺩﻋﻰ )ﻣﺣﻣﻝ ﺷﻳﻔﺭﺓ ﺍﻟﺗﺷﻐﻳﻝ( ﺑﺗﻬﻳﺋﺔ ﺍﻟﺟﻬﺎﺯ‬
main parts of the computer are OK and working. After that, it
loads the central part of the operating system, which is called ‫ ﻓﻳﻘﻭﻡ ﺑﺩﺍﻳﺔ ﺑﻔﺣﺹ ﺟﻣﻳﻊ ﺍﻷﺟﺯﺍء ﺍﻟﺭﺋﻳﺳﻳﺔ‬.‫ﻟﻠﻌﻣﻝ‬
‫ﻟﻠﺣﺎﺳﻭﺏ ﻣﻥ ﺫﺍﻛﺭﺓ ﺭﺋﻳﺳﻳﺔ ﻭﻟﻭﺣﺔ ﺍﻟﻣﻔﺎﺗﻳﺢ‬
the kernel, from the hard disk into a special place in the main
‫ﻭﺍﻟﺷﺎﺷﺔ ﻭﺍﻟﻘﺭﺹ ﺍﻟﺻﻠﺏ ﻭﻏﻳﺭﻫﺎ ﻟﻠﺗﺄﻛﺩ ﻣﻥ‬
memory, as shown in figure 1-2 above. The kernel takes over
‫ ﺛﻡ ﻳﻘﻭﻡ ﺑﺗﺣﻣﻳﻝ ﺍﻟﺟﺯء‬.‫ﻭﺟﻭﺩﻫﺎ ﻭﺳﻼﻣﺔ ﻋﻣﻠﻬﺎ‬
and starts to work. It takes control of the computer by first
(‫ﺍﻟﺭﺋﻳﺳﻲ ﻣﻥ ﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﻭﺍﻟﺫﻱ ﻳﺳﻣﻰ )ﺍﻟﻧﻭﺍﺓ‬
checking all the hardware components connected to the
‫ﺇﻟﻰ ﺍﻟﻣﻛﺎﻥ ﺍﻟﻣﺧﺻﺹ ﻟﻪ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ‬

3
Practical Data Structures with C++, C#, and Java

computer, and then it prepares the user interface (UI) that is ‫ ﻭﺑﻌﺩ ﺫﻟﻙ ﻳﻘﻭﻡ ﻫﺫﺍ ﺍﻟﺟﺯء ﻭﺍﻟﺫﻱ ﻳﻛﻭﻥ‬.‫ﺍﻟﺭﺋﻳﺳﻳﺔ‬
the desktop. ‫ﻋﺎﺩﺓ ﻣﻭﺟﻭﺩ ﻋﻠﻰ ﺍﻟﻘﺭﺹ ﺍﻟﺻﻠﺏ ﺑﺎﻟﻌﻣﻝ ﻋﻠﻰ‬
‫ﺗﻧﻅﻳﻡ ﻋﻣﻝ ﺍﻟﺣﺎﺳﻭﺏ ﻭﺍﻟﺗﺣﻛﻡ ﻓﻳﻪ ﻭﺗﻁﻭﻳﻌﻪ‬
Once it is ready, it silently waits for us to interact with the .‫ﻟﻠﻣﺳﺗﺧﺩﻡ ﻟﻼﺳﺗﻔﺎﺩﺓ ﻣﻧﻪ ﺑﺎﻟﺷﻛﻝ ﺍﻟﻣﻧﺎﺳﺏ‬
computer. For example, if we want to use the calculator, we ‫ﻓﻌﻧﺩﻣﺎ ﻧﺭﻳﺩ ﺗﺷﻐﻳﻝ ﺑﺭﻧﺎﻣﺞ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ ﻣﺛﻼ ﻓﺈﻧﻧﺎ‬
double click on its icon. We are commanding the operating ‫ﻧﻘﻭﻡ ﺑﺎﻟﻧﻘﺭ ﺑﺎﻟﻔﺄﺭﺓ ﻋﻠﻰ ﺍﻷﻳﻘﻭﻧﺔ ﺍﻟﻣﺧﺻﺻﺔ ﻟﻶﻟﺔ‬
system to start the calculator for us. The OS does that by ‫ ﻭﻛﺄﻧﻧﺎ ﻧﺧﺎﻁﺏ ﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﻭﻧﻁﻠﺏ ﻣﻧﻪ‬،‫ﺍﻟﺣﺎﺳﺑﺔ‬
loading a copy of the calculator program, which resides ‫ ﻓﻳﻘﻭﻡ ﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﺑﺩﻭﺭﻩ‬.‫ﺗﺷﻐﻳﻝ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ ﻟﻧﺎ‬
originally on the hard disk into the main memory. To be more ‫ﺑﺗﺣﻣﻳﻝ ﻧﺳﺧﺔ ﻣﻥ ﺑﺭﻧﺎﻣﺞ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ ﺇﻟﻰ ﺍﻟﻣﻛﺎﻥ‬
specific, it loads the copy into a special place called the code ‫ﺍﻟﻣﺧﺻﺹ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﺍﻟﻌﺷﻭﺍﺋﻳﺔ ﻳﺳﻣﻰ‬
segment, as shown in figure 1-2. ‫ﻗﺳﻡ ﺍﻟﺷﻳﻔﺭﺓ ﺣﻳﺙ ﻳﺗﻡ ﺍﻟﺗﻧﻔﻳﺫ ﻋﻥ ﻁﺭﻳﻖ ﺍﻧﺗﻘﺎﻝ‬
‫ﺍﻷﻭﺍﻣﺭ ﻣﻥ ﻗﺳﻡ ﺍﻟﺷﻳﻔﺔ ﺇﻟﻰ ﻭﺣﺩﺓ ﺍﻟﻣﻌﺎﻟﺟﺔ ﺍﻟﻣﻌﺎﻟﺞ‬
Once the OS loads the calculator program into memory, the .‫ﺍﻟﻣﺭﻛﺯﻳﺔ ﺑﺳﺭﻋﺔ ﻓﺎﺋﻘﺔ‬
lines of the code that are called instructions are fetched into
the CPU one by one. The CPU is connected directly to the ‫ﻭﻣﻥ ﻫﺫﻩ ﺍﻷﻭﺍﻣﺭ ﺗﻬﻳﺋﺔ ﺷﻛﻝ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ ﻋﻠﻰ‬
memory; it receives instructions and performs the required ‫ﺷﺎﺷﺔ ﺳﻁﺢ ﺍﻟﻣﻛﺗﺏ ﻛﻲ ﻧﺗﻔﺎﻋﻝ ﻣﻌﻬﺎ ﻋﻧﺩ‬
tasks. Like any program, the calculator first prepares its user ‫ﺍﻻﺳﺗﺧﺩﺍﻡ ﻭﺃﻳﺿﺎ ﺣﺟﺯ ﻣﻛﺎﻥ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ‬
interface that is the window with the display and the buttons ‫ ﻭﻫﺫﻩ‬.‫ ﻭﻫﺫﺍ ﺍﻟﻣﻛﺎﻥ ﻳﺳﻣﻰ ﻗﺳﻡ ﺍﻟﺑﻳﺎﻧﺎﺕ‬،‫ﻟﻠﺑﻳﺎﻧﺎﺕ‬
containing numbers and operations. After that, it waits for us ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻫﻲ ﺍﻷﻋﺩﺍﺩ ﺍﻟﺗﻲ ﺳﻧﺩﺧﻠﻬﺎ ﻻﺳﺗﺧﺩﺍﻣﻬﺎ ﻓﻲ‬
to start using it. We do that by entering numbers and ‫ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﺣﺳﺎﺑﻳﺔ ﻭﻣﻥ ﺛﻡ ﺇﻅﻬﺎﺭ ﺍﻟﻧﺗﺎﺋﺞ ﻓﻲ ﺍﻟﻣﻛﺎﻥ‬
operations to perform the calculations. The numbers we enter .‫ﺍﻟﻣﺧﺻﺹ ﻟﻬﺎ ﻋﻠﻰ ﺍﻟﺷﺎﺷﺔ‬
for calculation is data that goes into a special place in the main
memory called the data segment. How does the calculator ‫ﺇﺫﺍ ً ﻛﻳﻑ ﻳﻘﻭﻡ ﺑﺭﻧﺎﻣﺞ ﺍﻵﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ ﺑﺣﺟﺯ ﻣﻛﺎﻧﺎ‬
program reserve a space for this data in memory? In other ‫ﻟﻬﺫﻩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﺃﻱ ﺑﻣﻌﻧﻰ ﺁﺧﺭ ﻛﻳﻑ ﻳﻘﻭﻡ ﺑﻬﻳﻛﻠﺔ‬
words, how does the program structure the data in memory? If ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺍﻟﺫﺍﻛﺭﺓ؟ ﻭﺇﺫﺍ ﺃﺭﺩﻧﺎ ﺃﻥ ﻧﺑﺭﻣﺞ ﺁﻟﺔ‬
we are going to code our programs, how do we deal with the ‫ﺣﺎﺳﺑﺔ ﺑﺄﻧﻔﺳﻧﺎ ﺃﻭ ﺃﻱ ﺑﺭﻧﺎﻣﺞ ﺁﺧﺭ ﻓﻛﻳﻑ ﻧﺗﻌﺎﻣﻝ ﻣﻊ‬
different types of data such as numbers and text? We shall ‫ﺍﻷﻧﻣﺎﻁ ﺍﻟﻣﺧﺗﻠﻔﺔ ﻣﻥ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻣﺛﻝ ﺍﻷﻋﺩﺍﺩ‬
present these matters in detail in the next chapter. .‫ﻭﺍﻟﻧﺻﻭﺹ ﻭﻏﻳﺭﻫﺎ؟ ﻫﺫﺍ ﻣﺎ ﺳﻧﻘﻭﻡ ﺑﺷﺭﺣﻪ ﻻﺣﻘﺎ‬

1.3 RANDOM ACCESS MEMORY (RAM)

‫ﺍﻟﻭﺣﺩﺓ ﺍﻷﺳﺎﺳﻳﺔ ﻓﻲ ﺍﻟﺣﺎﺳﻭﺏ ﻫﻲ ﺍﻟﺑﺕ ﻭﺍﻟﺗﻲ ﺗﺄﺧﺫ ﺇﺣﺩﻯ‬


The smallest unit of data in the computer is the bit, which
‫ ﻓﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﻋﺑﺎﺭﺓ ﻋﻥ‬.‫ﺍﻟﻘﻳﻣﺗﻳﻥ ﺍﻣﺎ ﺻﻔﺭ ﺃﻭ ﻭﺍﺣﺩ‬
takes one of two values: zero (OFF) or one (ON). The
‫ ﻭﻛﻝ ﺧﻠﻳﺔ ﻣﻥ ﻫﺫﻩ‬،‫ﻣﺻﻔﻭﻓﺔ ﻛﺑﻳﺭﺓ ﻣﻥ ﺍﻟﺧﻼﻳﺎ ﺍﻻﻟﻛﺗﺭﻭﻧﻳﺔ‬
computer’s main memory is a vast array of electronic
‫ﺍﻟﺧﻼﻳﺎ ﻗﺎﺩﺭﺓ ﻋﻠﻰ ﺗﺧﺯﻳﻥ ﺷﺣﻧﺔ ﻛﻬﺭﺑﺎﺋﻳﺔ ﺃﻭ ﻋﺩﻡ ﻭﺟﻭﺩ‬
cells; each cell can store an electrical charge. The state
of each cell is either ON or OFF, one or zero. Each ‫ ﻓﺈﻥ ﺃﻱ ﻋﺩﺩ ﻳﺗﻡ ﺍﻟﺗﻌﺎﻣﻝ ﻣﻌﻪ ﻓﻲ ﺍﻟﺣﺎﺳﻭﺏ‬. ‫ﻫﺫﻩ ﺍﻟﺷﺣﻧﺔ‬
number stored in the memory consists of a series of ‫ ﻭﻓﻲ ﺍﻟﺣﻘﻳﻘﺔ ﻓﺈﻥ ﺃﻱ ﻧﻭﻉ‬،‫ﻫﻭ ﻣﻥ ﻣﺿﺎﻋﻔﺎﺕ ﻫﺫﻳﻥ ﺍﻟﻌﺩﺩﻳﻥ‬
‫)ﻭﻳﺳﻣﻰ ﻧﻣﻁ( ﻣﻥ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻣﺛﻝ ﺍﻟﻧﺻﻭﺹ ﻭﺣﺗﻰ ﺍﻟﺻﻭﺭ‬
zeros and ones. All types of data stored in memory are
‫ﻭﺍﻷﺻﻭﺍﺕ ﺗﺣﻔﻅ ﻓﻲ ﺍﻟﺣﺎﺳﻭﺏ ﻋﻠﻰ ﺷﻛﻝ ﺳﻼﺳﻝ ﻣﻥ‬
combinations of zeros and ones. Unlike humans that use
‫ ﻓﺎﻟﺣﺎﺳﻭﺏ ﻳﻌﻣﻝ ﺑﺎﻟﻧﻅﺎﻡ ﺍﻟﺛﻧﺎﺋﻲ‬.‫ﺍﻷﺻﻔﺎﺭ ﻭﺍﻟﻭﺍﺣﺩﺍﺕ‬
the decimal system, computers use a binary system.
Every digit stored in memory is converted to zeros and ‫ ﺇﺫﺍ ً ﻛﻳﻑ ﻳﺗﻡ ﺗﺧﺯﻳﻥ ﻫﺫﻩ ﺍﻟﺑﻳﺎﻧﺎﺕ‬.‫ﻭﻟﻳﺱ ﺍﻟﻌﺷﺭﻱ ﻛﺎﻹﻧﺳﺎﻥ‬
ones according to a standard called the American ‫ﻭﺍﻟﺗﻌﺎﻣﻝ ﻣﻌﻬﺎ؟ ﻳﺳﺗﺧﺩﻡ ﺍﻟﺣﺎﺳﻭﺏ ﺟﺩﻭﻻ ﻳﺑﻳﻥ ﺍﻟﺭﻣﺯ‬
‫ﺍﻟﺛﻧﺎﺋﻲ ﺍﻟﻣﺭﺍﺩﻑ ﻟﻛﻝ ﺣﺭﻑ ﻭﻫﻭ ﻋﺑﺎﺭﺓ ﻋﻥ ﺳﻠﺳﻠﺔ ﻣﻥ‬
Standard Code for Information Interchange (ASCII).
‫ﺍﻷﺻﻔﺎﺭ ﻭﺍﻟﻭﺍﺣﺩﺍﺕ ﻭﺍﻟﺗﻲ ﻳﻣﻛﻥ ﺗﺣﻭﻳﻠﻬﺎ ﺇﻟﻰ ﻗﻳﻣﺔ ﻋﺷﺭﻳﺔ‬
Each code has a decimal value, as shown in figure 1-3.
.3-1‫ﻛﻣﺎ ﻣﺑﻳﻥ ﻓﻲ ﺍﻟﺷﻛﻝ‬

4
M.A. Eljinini

According to the ASCII table, each code is made of seven ‫ﻳﺳﻣﻰ ﻫﺫﺍ ﺍﻟﺟﺩﻭﻝ ﺑﺟﺩﻭﻝ ﺍﻟﺭﻣﻭﺯ ﺍﻷﻣﺭﻳﻛﻳﺔ ﺍﻟﻘﻳﺎﺳﻳﺔ‬
digits of zeros and ones. If we convert a series of seven ‫ ﻓﻛﻝ ﺭﻣﺯ ﻳﺗﺄﻟﻑ ﻣﻥ ﺳﺑﻊ ﺧﺎﻧﺎﺕ ﺃﻱ ﻣﻥ‬.‫ﻟﺗﺑﺎﺩﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ‬
ones to a decimal value, we get the value 127. ‫ ﻣﻥ‬128 ‫ ﻭﺑﺫﻟﻙ ﻳﺳﻣﺢ ﻫﺫﺍ ﺍﻟﺟﺩﻭﻝ ﺑﺗﻣﺛﻳﻝ‬127 ‫ ﺇﻟﻰ‬0
Therefore, we have a range from 0 to 127 different values ‫ﺍﻟﺭﻣﻭﺯ ﻭﺍﻟﺗﻲ ﻛﺎﻧﺕ ﻓﻲ ﺑﺩﺍﻳﺎﺕ ﻋﻬﺩ ﺍﻟﺣﻭﺍﺳﻳﺏ ﻛﺎﻓﻳﺔ‬
that the ASCII table can represent. This was enough ‫ﻟﺗﻐﻁﻳﺔ ﺟﻣﻳﻊ ﺍﻟﺣﺭﻭﻑ ﺍﻟﻣﺳﺗﻌﻣﻠﺔ ﺣﻳﺙ ﻛﺎﻧﺕ ﺍﻟﻠﻐﺔ‬
values for early computers to cover all the used symbols, ‫ ﻭﻣﻊ‬.‫ﺍﻻﻧﺟﻠﻳﺯﻳﺔ ﻫﻲ ﺍﻟﻭﺣﻳﺩﺓ ﺍﻟﻣﻌﺗﻣﺩﺓ ﻓﻲ ﺃﻧﻅﻣﺔ ﺍﻟﺣﺎﺳﻭﺏ‬
taking into consideration that the English Language was ‫ﺍﻟﺗﻁﻭﺭ ﺍﻟﻌﺎﻟﻣﻲ ﻓﻲ ﺍﺳﺗﺧﺩﺍﻣﺎﺕ ﺍﻟﺣﺎﺳﻭﺏ ﺃﺻﺑﺢ ﻻ ﺑﺩ ﻣﻥ‬
the only language used at that time. During the years, ‫ ﺑﺎﻹﺿﺎﻓﺔ‬،‫ﺗﻭﺳﻳﻊ ﺍﻟﺟﺩﻭﻝ ﻟﻳﺷﻣﻝ ﺍﻟﻠﻐﺎﺕ ﺍﻟﻌﺎﻟﻣﻳﺔ ﺍﻷﺧﺭﻯ‬
many coding systems have been developed to handle ‫ ﻭﻓﻲ ﺑﺩﺍﻳﺔ ﺍﻟﺗﺳﻌﻳﻧﺎﺕ ﺗﻡ‬،‫ﺇﻟﻰ ﺑﻌﺽ ﺍﻟﺭﻣﻭﺯ ﻭﺍﻷﺷﻛﺎﻝ‬
text in so many different languages across the globe. In ‫ﺇﻧﺷﺎء ﺟﺩﻭﻝ ﺍﻟﺭﻣﺯ ﺍﻟﻣﻭﺣﺩ ﻭﺍﻟﺫﻱ ﻳﺣﺗﻭﻱ ﻋﻠﻰ ﺃﻻﻑ‬
the early nineties, a new coding system called Unicode .‫ﺍﻟﺭﻣﻭﺯ ﻭﻣﻧﻬﺎ ﺭﻣﻭﺯ ﻟﻸﺣﺭﻑ ﺍﻟﻌﺭﺑﻳﺔ‬
was developed which contains thousands of symbols that
can handle most written text such as Arabic.
We have mentioned earlier that the bit is
the smallest unit of data that can hold one
of two values. A larger unit is the byte,
which consists of eight bits.
Today most computers use 64-bit
architecture. Data moves from memory to
the CPU in a path called the data bus with
a width of 64 bits (8 bytes). Therefore, the
memory is made of groups of cells; each
consists of 64 bits. A group of 64 bits is
equal to one word, and each word in the
computer memory has an address.
Imagine that the memory of the computer
consists of boxes where each box is
labeled with an address and can hold 64
bits of data. One of the main tasks we do
when writing computer programs is
reserving memory spaces for our data,
which are called variables. For example, if Figure 1-3: ASCII Table
we want to write a small program for
adding any two numbers, we need to do ‫ﻭﻣﻥ ﺍﻟﻭﺣﺩﺍﺕ ﺍﻷﺧﺭﻯ ﺍﻟﺗﻲ ﻳﺗﻡ ﺍﻟﺗﻌﺎﻣﻝ ﻣﻌﻬﺎ ﻓﻲ ﺃﻧﻅﻣﺔ ﺍﻟﺣﺎﺳﻭﺏ ﻟﻔﻬﻡ ﺍﻟﺑﻳﺎﻧﺎﺕ‬
the following steps: .‫ ﺑﺕ‬8 ‫ﻫﻲ ﺍﻟﺑﺎﻳﺕ ﻭﺍﻟﺗﻲ ﺗﺳﺎﻭﻱ‬
1. Declare three variables and give them
meaningful names. For example, ‫ﺇﻥ ﻣﻌﻅﻡ ﺃﺟﻬﺯﺓ ﺍﻟﺣﺎﺳﻭﺏ ﻓﻲ ﺃﻳﺎﻣﻧﺎ ﻫﺫﻩ ﻣﺯﻭﺩﻩ ﺑﺫﺍﻛﺭﺓ ﺣﻳﺙ ﺃﻥ ﺳﻌﺔ ﺍﻟﻣﻣﺭ‬
num1, num2, and result. ‫ ﺑﺕ ﺑﻧﻔﺱ‬64 ‫ ﺃﻱ ﺍﻧﻬﺎ ﻗﺎﺩﺭﺓ ﻋﻠﻰ ﻧﻘﻝ‬،(‫ ﺑﺎﻳﺕ‬8) ‫ ﺑﺕ‬64 ‫ﺍﻟﻧﺎﻗﻝ ﻟﻠﺑﻳﺎﻧﺎﺕ ﻓﻳﻬﺎ‬
2. Define their types based on user ‫ ﻭﻳﻣﻛﻥ ﺍﻟﻘﻭﻝ ﺇﻥ ﺍﻟﺫﺍﻛﺭﺓ ﻣﻘﺳﻣﺔ ﺇﻟﻰ ﻣﺟﻣﻭﻋﺎﺕ ﻣﻥ‬.‫ﺍﻟﻭﻗﺕ ﻭﺑﺷﻛﻝ ﻣﺗﻣﺎﺛﻝ‬
requirements. For example, (int) for ‫ ﺗﺧﻳﻝ‬.‫ ﻭﻟﻛﻝ ﻛﻠﻣﺔ ﻋﻧﻭﺍﻥ‬،‫ ﺑﺕ ﻭﺗﺳﻣﻰ ﻛﻠﻣﺔ‬64 ‫ﺍﻟﺧﻼﻳﺎ ﺳﻌﺔ ﻛﻝ ﻣﺟﻣﻭﻋﺔ ﻣﻧﻬﺎ‬
integers and (float) for real numbers. ‫ﺃﻥ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﻣﻘﺳﻣﺔ ﺇﻟﻰ ﺻﻧﺎﺩﻳﻖ ﻛﻝ ﺻﻧﺩﻭﻕ ﻳﺣﺗﻭﻱ ﻋﻠﻰ ﻛﻠﻣﺔ‬
We discuss data types in more detail in ‫ ﻓﻣﻥ ﺍﻷﺷﻳﺎء ﺍﻻﺳﺎﺳﻳﺔ ﻋﻧﺩ ﻛﺗﺎﺑﺔ‬.‫ﻭﻧﺳﺗﻁﻳﻊ ﺍﻟﻭﺻﻭﻝ ﺇﻟﻳﻬﺎ ﻋﻥ ﻁﺭﻳﻖ ﻋﻧﻭﺍﻧﻬﺎ‬
the next chapter. ‫ﺍﻟﺑﺭﺍﻣﺞ ﻫﻭ ﺣﺟﺯ ﺃﻣﺎﻛﻥ ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﻟﻠﺑﻳﺎﻧﺎﺕ ﻭﺗﻛﻭﻥ ﻋﻠﻰ ﺷﻛﻝ‬
3. When our program runs, the operating ‫ ﻓﻣﺛﻼ ﺇﺫﺍ ﺃﺭﺩﻧﺎ ﻛﺗﺎﺑﺔ ﺑﺭﻧﺎﻣﺞ ﺑﺳﻳﻁ ﻳﻘﻭﻡ ﺑﺈﺩﺧﺎﻝ ﻋﺩﺩﻳﻥ ﺻﺣﻳﺣﻳﻥ‬.‫ﻣﺗﻐﻳﺭﺍﺕ‬
system reserves space for these ‫ﻭﺟﻣﻌﻬﻣﺎ ﻭﻋﺭﺽ ﺍﻟﻧﺎﺗﺞ ﻓﺈﻧﻧﺎ ﻧﺣﺗﺎﺝ ﺇﻟﻰ ﺣﺟﺯ ﻣﻛﺎﻧﻳﻥ ﻟﻬﻣﺎ ﻓﻲ ﺍﻟﺫﺍﻛﺭﺓ‬
variables in the data segment of the (num2) 2‫( ﻭﻋﺩﺩ‬num1) 1‫( ﺃﻭ ﻋﺩﺩ‬y) ‫( ﻭ ﺹ‬x) ‫ﻭﺗﺳﻣﻳﺗﻬﻣﺎ ﻣﺛﻼ ﺱ‬
main memory. ‫ ﻭﻋﻧﺩ‬،‫ﻭﺃﻳﺿﺎ ﻳﺟﺏ ﺍﻟﺗﺻﺭﻳﺢ ﺑﻧﻣﻁ ﻫﺫﻩ ﺍﻟﻣﺗﻐﻳﺭﺍﺕ ﺃﻱ ﻣﻥ ﻧﻭﻉ ﻋﺩﺩ ﺻﺣﻳﺢ‬
‫ﺗﻧﻔﻳﺫ ﺍﻟﺑﺭﻧﺎﻣﺞ ﻳﻘﻭﻡ ﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﺑﺗﺣﻣﻳﻝ ﺍﻟﺑﺭﻧﺎﻣﺞ ﺇﻟﻰ ﺍﻟﻣﻛﺎﻥ ﺍﻟﻣﺧﺻﺹ ﻟﻪ‬

5
Practical Data Structures with C++, C#, and Java

4. After that, the program asks the user to ‫ﻓﻲ ﺫﺍﻛﺭﺓ ﺍﻟﺣﺎﺳﻭﺏ ﻭﺑﻌﺩﻫﺎ ﻳﻁﻠﺏ ﺍﻟﺑﺭﻧﺎﻣﺞ ﻣﻥ ﻧﻅﺎﻡ ﺍﻟﺗﺷﻐﻳﻝ ﺗﺧﺻﻳﺹ ﻭﺣﺟﺯ‬
input two numbers, then perform the ‫ﺍﻻﻣﺎﻛﻥ ﺍﻟﻼﺯﻣﺔ ﻟﻬﺫﻳﻥ ﺍﻟﻣﺗﻐﻳﺭﻳﻥ ﻓﻲ ﺍﻟﻣﻛﺎﻥ ﺍﻟﻣﺧﺻﺹ ﻟﺣﺟﺯ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ‬
addition and display the result. ‫ ﻭﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﺈﺭﺟﺎﻉ ﺍﻟﻌﻧﺎﻭﻳﻥ ﺇﻟﻰ ﺍﻟﺑﺭﻧﺎﻣﺞ ﻛﻣﺭﺟﻊ ﻳﺗﻌﺎﻣﻝ ﻣﻌﻪ ﻋﻧﺩ‬،‫ﺍﻟﺫﺍﻛﺭﺓ‬
‫ﺗﺧﺯﻳﻥ ﺍﻷﻋﺩﺍﺩ ﺍﻟﻣﺭﺍﺩ ﺟﻣﻌﻬﺎ ﻛﻣﺎ ﻓﻲ ﻫﺫﺍ ﺍﻟﻣﺛﺎﻝ ﻭﺍﻟﺫﻱ ﺳﻳﻘﻭﻡ ﺍﻟﻣﺳﺗﺧﺩﻡ‬
The data types (int) and (float) are called .‫ﺑﺈﺩﺧﺎﻟﻬﻣﺎ ﻻﺣﻘﺎ ﺧﻼﻝ ﻣﺭﺣﻠﺔ ﺍﻟﺗﻧﻔﻳﺫ‬
primitive data types. They are simple, and
we cannot divide them into smaller units.
On the other hand, arrays are more ‫ﻳﻌﺗﺑﺭ ﺍﻟﻧﻣﻁ )ﻋﺩﺩ ﺻﺣﻳﺢ( ﻣﻥ ﺃﻧﻣﺎﻁ ﺍﻟﺑﻳﺎﻧﺎﺕ ﺍﻟﺑﺳﻳﻁﺔ ﺃﻭ ﺍﻟﺑﺩﺍﺋﻳﺔ ﻭﻫﻧﺎﻟﻙ ﺃﻧﻣﺎﻁ‬
complex data types that we discuss in ‫ﺃﺧﺭﻯ ﻣﻧﻬﺎ ﻣﺛﻝ )ﺣﺭﻑ( ﻟﻠﺗﻌﺎﻣﻝ ﻣﻊ ﺍﻟﺣﺭﻭﻑ ﺑﺷﻛﻝ ﻣﻧﻔﺭﺩ ﻭﻧﻣﻁ )ﻋﺩﺩ‬
chapter three. ‫ﻋﺷﺭﻱ( ﻭﻏﻳﺭﻫﺎ ﻭﺍﻟﺗﻲ ﺳﻧﻘﻭﻡ ﺑﻌﺭﺿﻬﺎ ﻓﻲ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺛﺎﻧﻳﺔ ﻋﻧﺩ ﺍﻟﺗﻛﻠﻡ ﻋﻥ ﻟﻐﺎﺕ‬
‫ ﺃﻣﺎ ﺍﻟﻣﺻﻔﻭﻓﺎﺕ ﻓﻬﻲ ﻣﻥ ﺍﻷﻧﻣﺎﻁ ﺍﻟﻣﺭﻛﺑﺔ ﻭﺍﻟﺗﻲ ﺳﻧﻌﺭﺿﻬﺎ ﺑﺎﻟﺗﻔﺻﻳﻝ‬.‫ﺍﻟﺑﺭﻣﺟﺔ‬
.‫ﻓﻲ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺛﺎﻟﺛﺔ‬

1.4 SOFTWARE

Computer programs are groups of instructions that perform ‫ﺑﺭﻣﺟﻳﺎﺕ ﺍﻟﺣﺎﺳﻭﺏ ﻫﻲ ﻋﺑﺎﺭﺓ ﻋﻥ ﻣﺟﻣﻭﻋﺎﺕ ﻣﻥ‬
particular tasks and are converted into machine language ‫ﺍﻟﺗﻌﻠﻳﻣﺎﺕ ﺃﻭ ﺍﻷﻭﺍﻣﺭ ﻣﻛﺗﻭﺑﺔ ﺑﻠﻐﺔ ﺍﻵﻟﺔ ﻭﺗﻘﻭﻡ ﺑﻣﻬﺎﻡ‬
when they are executed. There are two major types of ‫ ﻧﻅﻡ ﺍﻟﺗﺷﻐﻳﻝ‬:‫ ﻭﻫﻧﺎﻟﻙ ﻧﻭﻋﺎﻥ ﻣﻥ ﺍﻟﺑﺭﻣﺟﻳﺎﺕ‬.‫ﻣﻌﻳﻧﺔ‬
programs: Operating systems like Windows and Linux, ‫ﻛﻧﻅﺎﻡ ﻭﻳﻧﺩﻭﺯ ﻭﻟﻳﻧﻛﺱ ﻭﻏﻳﺭﻫﺎ ﻭﺍﻟﺗﻲ ﺗﺗﺣﻛﻡ ﺑﺎﻟﻛﻳﺎﻥ‬
which are made to control the computer hardware and ‫ﺍﻟﻣﺎﺩﻱ ﻟﻠﺣﺎﺳﻭﺏ ﻭﺗﻭﻓﺭ ﻟﻠﻣﺳﺗﺧﺩﻡ ﺑﻳﺋﺔ ﺗﻔﺎﻋﻠﻳﺔ ﻣﻊ‬
provide users with a productive environment for interacting ‫ ﻭﺍﻟﻧﻭﻉ ﺍﻟﺛﺎﻧﻲ ﻫﻲ ﺃﻧﻅﻣﺔ ﺗﻁﺑﻳﻘﺎﺕ ﺍﻟﺣﺎﺳﻭﺏ‬.‫ﺍﻟﺣﺎﺳﻭﺏ‬
and running programs. The other type is computer ‫ﻭﻣﻧﻬﺎ ﺑﺭﻣﺟﻳﺎﺕ ﻣﻌﺎﻟﺟﺔ ﺍﻟﻧﺻﻭﺹ ﻭﺑﺭﻣﺟﻳﺎﺕ ﺗﺻﻔﺢ‬
applications, for example, there are applications for ‫ﺍﻟﻭﻳﺏ ﻭﺑﺭﻣﺟﻳﺎﺕ ﻗﻭﺍﻋﺩ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﺑﺭﻣﺟﻳﺎﺕ ﺍﻷﻟﻌﺎﺏ‬
processing text, browsing the web, playing games, ‫ ﻭﻏﻳﺭﻫﺎ ﺍﻟﻛﺛﻳﺭ ﻭﺍﻟﺗﻲ ﺗﺳﺎﻋﺩ‬،‫ﻭﺑﺭﻣﺟﻳﺎﺕ ﺍﻻﻟﺔ ﺍﻟﺣﺎﺳﺑﺔ‬
searching databases, performing complex calculations, ‫ ﻭﻫﺫﻩ ﺍﻟﺑﺭﻣﺟﻳﺎﺕ ﻗﺎﻡ‬.‫ﺍﻹﻧﺳﺎﻥ ﻓﻲ ﺷﺗﻰ ﺍﻟﻣﺟﺎﻻﺕ‬
and just about anything that we may use in our daily lives. ‫ﺑﺗﺻﻣﻳﻣﻬﺎ ﻭﺑﺭﻣﺟﺗﻬﺎ ﺃﺷﺧﺎﺹ ﻫﻡ ﻣﺑﺭﻣﺟﻭﻥ ﺍﺣﺗﺭﻓﻭﺍ‬
Computer programs are designed and implemented by ‫ ﻭﻋﺎﺩﺓ ﻳﻌﻣﻠﻭﻥ ﻓﻲ ﺷﺭﻛﺎﺕ ﻣﺗﺧﺻﺻﺔ‬،‫ﻣﻬﻧﺔ ﺍﻟﺑﺭﻣﺟﺔ‬
programmers. Programmers usually work for companies ‫ﻣﺛﻝ ﺷﺭﻛﺔ ﻣﺎﻳﻛﺭﻭﺳﻭﻓﺕ ﻭﻏﻳﺭﻫﺎ ﺍﻟﻛﺛﻳﺭ ﻣﻥ ﺍﻟﺷﺭﻛﺎﺕ‬
like Microsoft and other international and local companies. .‫ ﻭﺑﻌﺿﻬﻡ ﻳﻌﻣﻝ ﻟﺣﺳﺎﺑﻪ ﺍﻟﺧﺎﺹ‬،‫ﺍﻟﻌﺎﻟﻣﻳﺔ ﻭﺍﻟﻣﺣﻠﻳﺔ‬
Some programmers are freelancers who do work on their ‫ﻭﻟﻛﻲ ﺗﺻﺑﺢ ﻣﺑﺭﻣﺟﺎ ﻣﺣﺗﺭﻓﺎ ﻻ ﺑﺩ ﻣﻥ ﺃﻥ ﺗﺗﻌﻠﻡ ﻣﻌﻣﺎﺭﻳﺔ‬
own. To become a professional programmer, we need to ‫ﺍﻟﺣﺎﺳﻭﺏ ﻭﺑﺭﻣﺟﺗﻪ ﺑﺎﺳﺗﺧﺩﺍﻡ ﺇﺣﺩﻯ ﻟﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ ﻣﺛﻝ‬
learn computer hardware and software. We need to ‫ ﻭﻣﻧﻬﺎ ﻛﻳﻔﻳﺔ ﺍﻟﺗﻌﺎﻣﻝ ﻣﻊ‬،‫ ﺃﻭ ﺟﺎﻓﺎ‬#‫ ﺃﻭ ﺳﻲ‬++‫ﺳﻲ‬
become fluent with at least one programming language, ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺑﺭﻣﺟﻳﺎﺕ ﺍﻟﺣﺎﺳﻭﺏ ﺍﻟﺗﻲ ﺗﺻﻣﻣﻬﺎ ﻭﺗﻛﺗﺑﻬﺎ‬
like C++, C#, or Java. We also need to learn how to .‫ﺑﻧﻔﺳﻙ‬
analyze and design programs.

1.5 SOFTWARE DEVELOPMENT

The main aim of studying data structures is to develop ‫ﺇﻥ ﺍﻟﻬﺩﻑ ﺍﻷﺳﺎﺳﻲ ﻣﻥ ﺩﺭﺍﺳﺔ ﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻫﻭ ﺍﺳﺗﺧﺩﺍﻣﻬﺎ‬
efficient software applications. There are several steps ‫ﻓﻲ ﺗﻁﻭﻳﺭ ﺍﻟﺑﺭﻣﺟﻳﺎﺕ ﺃﻱ ﺑﺭﻣﺟﺔ ﺍﻟﺗﻁﺑﻳﻘﺎﺕ ﻭﺍﻷﻧﻅﻣﺔ‬
that we need to learn, to develop functional applications, ‫ ﻭﻟﺻﻧﻊ ﻫﺫﻩ ﺍﻟﺗﻁﺑﻳﻘﺎﺕ ﻫﻧﺎﻟﻙ ﻋﺩﺩ ﻣﻥ ﺍﻟﺧﻁﻭﺍﺕ‬.‫ﺍﻟﺣﺎﺳﻭﺑﻳﺔ‬
which are free of errors. These steps are called the
‫ﺍﻟﺗﻲ ﻳﺟﺏ ﺍﺗﺑﺎﻋﻬﺎ ﻟﻠﻭﺻﻭﻝ ﺇﻟﻰ ﺗﻁﺑﻳﻘﺎﺕ ﻧﺎﺟﺣﺔ ﻭﺧﺎﻟﻳﺔ ﻣﻥ‬
problem-solving steps, and as follows:
:‫ ﻭﻫﺫﻩ ﺍﻟﺧﻁﻭﺍﺕ ﻫﻲ ﻛﺎﻟﺗﺎﻟﻲ‬،‫ﺍﻷﺧﻁﺎء‬
1. Study and understand the problem: This is the most ‫ ﻭﻫﺫﻩ‬:‫ ﺩﺭﺍﺳﺔ ﻭﻓﻬﻡ ﺍﻟﺗﻁﺑﻳﻖ )ﺍﻟﻧﻅﺎﻡ( ﺍﻟﻣﺭﺍﺩ ﺑﺭﻣﺟﺗﻪ‬.1
critical step. We need to understand what is ‫ﺍﻟﺧﻁﻭﺓ ﻣﻥ ﺃﻫﻡ ﺍﻟﺧﻁﻭﺍﺕ ﺣﻳﺙ ﻳﺗﻡ ﺗﺣﺩﻳﺩ ﻣﺗﻁﻠﺑﺎﺕ‬
required from our application, and what exactly it ‫ ﻭﻋﺎﺩﺓ ﻳﻘﻭﻡ‬.‫ﻭﺃﻫﺩﺍﻑ ﺍﻟﻧﻅﺎﻡ ﺍﻟﻣﺣﻭﺳﺏ ﺑﺷﻛﻝ ﺩﻗﻳﻖ ﺟﺩﺍ‬
should do. In large software production companies, ‫ﺍﻟﻣﺑﺭﻣﺞ ﺃﻭ ﻣﺣﻠﻝ ﺍﻟﻧﻅﻡ ﺑﺟﻣﻊ ﻛﻝ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ‬
persons called Systems Analysts collect all the ‫ﺍﻟﻧﻅﺎﻡ ﺍﻟﻣﺭﺍﺩ ﺣﻭﺳﺑﺗﻪ ﻭﻋﻣﻝ ﺍﻻﺳﺗﺑﻳﺎﻧﺎﺕ ﻭﺍﻟﻣﻘﺎﺑﻼﺕ‬

6
M.A. Eljinini

information about the application to be ‫ﻣﻊ ﺍﻷﺷﺧﺎﺹ ﺍﻟﻣﺳﺗﺧﺩﻣﻳﻥ ﻟﻠﻧﻅﺎﻡ ﺍﻟﻳﺩﻭﻱ ﺍﻟﺣﺎﻟﻲ ﻣﻥ‬
programmed. They usually conduct surveys and .‫ﻣﺩﺭﺍء ﻭﻣﻭﻅﻔﻳﻥ ﻭﻏﻳﺭﻫﻡ‬
conduct meetings with employees, managers, and ‫ ﻓﻲ ﻫﺫﻩ ﺍﻟﻣﺭﺣﻠﺔ ﻳﻘﻭﻡ ﺍﻟﻣﺣﻠﻝ‬:‫ﺗﺣﻠﻳﻝ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺣﺎﻟﻲ‬ .2
users to understand their requirements. ‫ﺑﺗﺣﻠﻳﻝ ﻛﻝ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﺍﻟﺗﻲ ﺣﺻﻝ ﻋﻠﻳﻬﺎ ﻭﻋﺎﺩﺓ ﻳﻘﻭﻡ‬
2. Analyze the problem (or the current manual ‫ﺑﻌﻣﻝ ﺭﺳﻭﻣﺎﺕ ﺗﺑﻳﻥ ﻛﻳﻔﻳﺔ ﺍﻧﺳﻳﺎﺏ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻓﻲ‬
system): System analysts analyze all the collected ‫ ﻭﻣﻥ ﺃﺷﻬﺭ ﻫﺫﻩ ﺍﻟﺭﺳﻭﻣﺎﺕ ﺃﻭ‬،‫ﺍﻟﻧﻅﺎﻡ ﺍﻟﺣﺎﻟﻲ‬
data. They draw diagrams showing the flow of data ‫ ﻧﻅﺎﻡ ﻣﺑﻳﻌﺎﺕ ﺣﻳﺙ ﻳﻘﻭﻡ‬:‫ ﻭﻣﺛﺎﻝ ﻋﻠﻰ ﺫﻟﻙ‬،‫ﺍﻟﻣﺧﻁﻁﺎﺕ‬
‫ﺍﻟﻣﻭﻅﻑ ﺑﺗﻌﺑﺋﺔ ﻧﻣﻭﺫﺝ ﻳﺣﺗﻭﻱ ﻋﻠﻰ ﻁﻠﺑﻳﻪ ﻣﻌﻳﻧﺔ‬
in the current system. These diagrams are called
‫ﻭﺗﺭﺳﻝ ﻧﺳﺧﺔ ﻣﻥ ﻫﺫﺍ ﺍﻟﻧﻣﻭﺫﺝ ﺇﻟﻰ ﺍﻟﻣﺣﺎﺳﺏ ﻛﻲ ﻳﻘﻭﻡ‬
Data Flow Diagrams (DFD). For example, in the
‫ ﻛﻣﺎ ﺗﺭﺳﻝ ﻧﺳﺧﺔ ﺇﻟﻰ‬،‫ﺑﺈﻋﺩﺍﺩ ﻓﺎﺗﻭﺭﺓ ﻟﻠﻣﺷﺗﺭﻱ‬
purchasing system, the employee fills a purchasing
‫ ﻭﺃﺧﺭﻯ ﻟﻺﺩﺍﺭﺓ ﻟﻣﺗﺎﺑﻌﺔ‬،‫ﺍﻟﻣﺳﺗﻭﺩﻉ ﻟﺗﺣﺿﻳﺭ ﺍﻟﻁﻠﺑﻳﺔ‬
order and sends a copy to the accounting ‫ ﺇﺫﺍ ﻣﻥ ﻣﻧﻅﻭﺭ ﺍﻟﻣﺣﻠﻝ ﻓﺈﻥ ﻫﺫﻩ ﻋﺑﺎﺭﺓ ﻋﻥ‬.‫ﺍﻟﻣﺑﻳﻌﺎﺕ‬
department to prepare the invoice. Another copy ‫ﺑﻳﺎﻧﺎﺕ ﺗﻧﺗﻘﻝ ﻋﺑﺭ ﺍﻷﻗﺳﺎﻡ ﺍﻟﻣﺧﺗﻠﻔﺔ ﻓﻲ ﺍﻟﺷﺭﻛﺔ ﻭﻣﻥ‬
goes to the warehouse to prepare the items for .‫ﺍﻟﻣﻬﻡ ﺟﺩﺍ ﻣﺗﺎﺑﻌﺗﻬﺎ ﻛﻭﻧﻬﺎ ﺟﺯء ﻣﻥ ﺍﻟﻧﻅﺎﻡ ﺍﻟﻣﺣﻭﺳﺏ‬
shipping. Another copy goes to the manager so he ‫ ﻓﻲ ﻫﺫﻩ ﺍﻟﻣﺭﺣﻠﺔ ﻳﻘﻭﻡ ﺍﻟﻣﺣﻠﻝ‬:‫ﺗﺻﻣﻳﻡ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ‬ .3
can follow up. From the perspective of the system ‫ﺑﺗﺻﻣﻳﻡ ﺷﺎﺷﺎﺕ ﺍﻟﻧﻅﺎﻡ ﻟﻛﻝ ﻋﻣﻠﻳﺔ ﻭﺃﻳﺿﺎ ﻗﻭﺍﻋﺩ‬
analyst, all these tasks are about data that flow ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﺑﻣﺎ ﻓﻳﻬﺎ ﻣﻥ ﺟﺩﺍﻭﻝ ﻭﺍﻟﻌﻼﻗﺎﺕ ﺑﻳﻥ ﻫﺫﻩ‬
throughout the different departments of the ‫ ﻭﺃﻳﺿﺎ ﺗﺻﻣﻳﻡ ﺍﻟﺗﻘﺎﺭﻳﺭ ﻭﻏﻳﺭﻫﺎ ﻭﺍﻟﺗﻲ ﺗﻣﺛﻝ‬،‫ﺍﻟﺟﺩﺍﻭﻝ‬
company. ‫ ﺑﺎﻹﺿﺎﻓﺔ‬،‫ﺍﻷﺟﺯﺍء ﺍﻟﺭﺋﻳﺳﻳﺔ ﻟﻠﻧﻅﺎﻡ ﺍﻟﻣﺣﻭﺳﺏ ﺍﻟﺟﺩﻳﺩ‬
3. System Design: This step is about the design of the .‫ﺇﻟﻰ ﺍﻟﺧﻭﺍﺭﺯﻣﻳﺎﺕ ﻟﻛﻝ ﻋﻣﻠﻳﺔ ﻳﻘﻭﻡ ﺑﻬﺎ ﺍﻟﻧﻅﺎﻡ‬
new application. There are many tasks to be ‫ ﻗﺩ ﻳﻘﻭﻡ ﻣﺑﺭﻣﺟﺎ ﻭﺍﺣﺩﺍ ﺑﺗﻧﻔﻳﺫ ﻫﺫﻩ‬:‫ﺑﺭﻣﺟﺔ ﺍﻟﻧﻅﺎﻡ‬ .4
performed. For example, the design of data input ‫ﺍﻟﺧﻁﻭﺓ ﻭﻓﻲ ﺍﻟﺷﺭﻛﺎﺕ ﺍﻟﻛﺑﻳﺭﺓ ﻗﺩ ﻳﻌﻬﺩ ﻟﻌﺩﺩ ﻣﻥ‬
screens, reports, and databases. The design of .‫ﺍﻟﻣﺑﺭﻣﺟﻳﻥ ﺇﻟﻰ ﺑﺭﻣﺟﺔ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ ﺑﺄﻗﺳﺎﻣﻪ ﺍﻟﻣﺧﺗﻠﻔﺔ‬
‫ﻭﻋﺎﺩﺓ ﻳﻘﻭﻡ ﺍﻟﻣﺣﻠﻝ ﺑﺗﺣﺩﻳﺩ ﻟﻐﺔ ﺍﻟﺑﺭﻣﺟﺔ ﺍﻷﻧﺳﺏ ﻹﺗﻣﺎﻡ‬
algorithms, which are the logic of the tasks that the
‫ ﻭﺣﺎﻟﻳﺎ ﻫﻧﺎﻟﻙ ﺍﻟﻣﺋﺎﺕ ﻣﻥ ﻟﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ‬.‫ﻫﺫﻩ ﺍﻟﻣﻬﻣﺔ‬
application needs to perform, like calculations and
‫ﺑﻌﺿﻬﺎ ﻋﺎﻡ ﺍﻻﺳﺗﺧﺩﺍﻡ ﻭﺑﻌﺿﻬﺎ ﻣﺗﺧﺻﺹ ﻷﻧﻅﻣﺔ‬
processing of data.
‫ ﻭﺟﻣﻳﻌﺎ ﺗﺷﺗﺭﻙ ﻓﻲ ﻧﻔﺱ ﺍﻟﻬﺩﻑ ﻭﻫﻭ ﺇﻧﺗﺎﺝ‬.‫ﻣﻌﻳﻧﺔ‬
4. System implementation: In this step, a suitable .‫ﺑﺭﻣﺟﻳﺎﺕ ﺗﻁﺑﻳﻘﻳﺔ‬
programming language is used to code the ‫ ﻳﻘﻭﻡ ﺍﻟﻣﺑﺭﻣﺞ ﺃﻭ ﺷﺧﺹ ﻣﻌﻳﻥ‬:‫ﺍﺧﺗﺑﺎﺭ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ‬ .5
programs and turn them into useful applications. ‫ ﻛﺄﻥ ﻳﻘﻭﻡ‬،‫ﻓﻲ ﺍﺧﺗﺑﺎﺭ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ ﺑﺷﻛﻝ ﻛﺎﻣﻝ ﻭﺷﺎﻣﻝ‬
5. Testing the new system: In large companies, a ‫ﺑﺗﺟﺭﺑﺔ ﺟﻣﻳﻊ ﺍﻻﺣﺗﻣﺎﻻﺕ ﻭﺗﺩﻭﻳﻥ ﻣﺎ ﻳﺣﺩﺙ ﻓﻲ ﻛﻝ‬
person who is called system tester performs all ‫ ﻭﺍﻟﻬﺩﻑ ﻫﻭ ﺇﻳﺟﺎﺩ ﺍﻷﺧﻁﺎء‬.‫ﺍﺣﺗﻣﺎﻝ ﻳﻘﻭﻡ ﺑﺎﺧﺗﺑﺎﺭﻩ‬
types of tests on the new system. For example, he ‫ﻭﺗﺻﺣﻳﺣﻬﺎ ﻗﺑﻝ ﺧﺭﻭﺝ ﺍﻟﺑﺭﻧﺎﻣﺞ ﺇﻟﻰ ﺍﻟﻭﺍﻗﻊ‬
may enter all types of data taking all the probabilities .‫ﻭﺍﺳﺗﺧﺩﺍﻣﻪ‬
that users may enter. In every step, he writes down ‫ ﻳﻘﻭﻡ ﺍﻟﻣﺣﻠﻝ ﺑﺗﻭﺛﻳﻖ ﺍﻟﻌﻣﻠﻳﺔ ﺑﺄﻛﻣﻠﻬﺎ ﺑﺎﻹﺿﺎﻓﺔ‬:‫ﺍﻟﺗﻭﺛﻳﻖ‬ .6
the results aiming to find and report errors. ‫ﺇﻟﻰ ﺗﻭﺛﻳﻖ ﻁﺭﻳﻘﺔ ﺍﺳﺗﺧﺩﺍﻡ ﺍﻟﺑﺭﻧﺎﻣﺞ ﻻﺳﺗﺧﺩﺍﻣﻪ ﻣﻥ ﻗﺑﻝ‬
6. Documentation: Besides documenting the whole ‫ﺍﻟﻣﺳﺗﺧﺩﻡ )ﺩﻟﻳﻝ ﺍﻟﻣﺳﺗﺧﺩﻡ( ﻭﺃﻳﺿﺎ ﺇﻟﻰ ﻛﻳﻔﻳﺔ ﺗﻧﺻﻳﺏ‬
process, programmers usually produce a book .‫ﺍﻟﺑﺭﻧﺎﻣﺞ ﻭﻣﺗﻁﻠﺑﺎﺗﻪ ﻣﻥ ﻣﻌﺩﺍﺕ ﻭﺑﺭﻣﺟﻳﺎﺕ ﻭﻏﻳﺭﻫﺎ‬
(User Guide), which shows how to set up and use
the new system in detail.

1.6 CASE STUDY: LIBRARY SYSTEM

In this part, we present a case study on how to ‫ﻛﻣﺎ ﺗﻡ ﺫﻛﺭﻩ ﺳﺎﺑﻘﺎ ﻓﺈﻥ ﻫﺫﺍ ﺍﻟﺟﺯء ﻳﻬﺩﻑ ﺇﻟﻰ ﻋﺭﺽ ﻛﻳﻔﻳﺔ ﺗﻁﻭﻳﺭ‬
develop an application for the library. Before we ‫ ﻭﻗﺑﻝ ﺍﻟﺑﺩء ﻓﻲ ﻛﺗﺎﺑﺔ ﺍﻟﻛﻭﺩ ﺑﻠﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ ﻻ ﺑﺩ ﻟﻧﺎ‬،‫ﺍﻟﺑﺭﺍﻣﺞ ﻭﺇﻋﺩﺍﺩﻫﺎ‬
start coding the application, we need to start .‫ﺍﻥ ﻧﺳﺗﻌﺭﺽ ﻛﻝ ﺧﻁﻭﺓ ﺑﺎﻟﺗﻔﺻﻳﻝ ﻛﻲ ﻧﺗﻣﻛﻥ ﻣﻥ ﻛﺗﺎﺑﺔ ﺑﺭﺍﻣﺞ ﻣﻔﻳﺩﺓ‬
from the beginning. Let us assume the library ‫ﻭﺳﻧﻘﻭﻡ ﺑﺫﻟﻙ ﻣﻥ ﺧﻼﻝ ﺷﺭﺡ ﻣﺛﺎﻻً ﻭﺍﻗﻌﻳﺎ ﻭﺍﻟﺫﻱ ﺳﻧﺳﺗﺧﺩﻣﻪ ﻓﻲ ﺷﺭﺡ‬
manager asked us to design a computer ‫ ﻓﻣﺛﻼ ﻟﻭ ﻓﺭﺿﻧﺎ ﺃﻥ ﺃﺣﺩ‬.‫ﻣﻔﺎﻫﻳﻡ ﻫﻳﺎﻛﻝ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺍﻟﻔﺻﻭﻝ ﺍﻟﻘﺎﺩﻣﺔ‬

7
Practical Data Structures with C++, C#, and Java

application to help her in the operations of ‫ﺍﻷﺷﺧﺎﺹ ﻳﻌﻣﻝ ﻣﺩﻳﺭﺍ ﻓﻲ ﺍﻟﻣﻛﺗﺑﺔ ﻗﺩ ﻁﻠﺏ ﻣﻧﺎ ﺃﻥ ﻧﺻﻣﻡ ﻟﻪ ﺑﺭﻧﺎﻣﺟﺎ‬
borrowing books. We need to understand all the ‫ ﺃﻱ ﺃﻥ‬.‫ﻟﻣﺳﺎﻋﺩﺗﻪ ﻓﻲ ﻋﻣﻠﻳﺔ ﺇﻋﺎﺭﺓ ﺍﻟﻛﺗﺏ ﺍﻟﻣﻭﺟﻭﺩﺓ ﻓﻲ ﺍﻟﻣﻛﺗﺑﺔ‬
details first. .‫ﺍﻟﻣﻁﻠﻭﺏ ﺑﺭﻣﺟﺔ ﻧﻅﺎﻡ ﺇﻋﺎﺭﺓ ﻛﺗﺏ ﻓﻲ ﻣﻛﺗﺑﺔ ﺍﻟﺟﺎﻣﻌﺔ ﻋﻠﻰ ﺳﺑﻳﻝ ﺍﻟﻣﺛﺎﻝ‬
.‫ﻭﻫﻧﺎ ﻻ ﺑﺩ ﻣﻥ ﺩﺭﺍﺳﺔ ﻭﻓﻬﻡ ﻣﺗﻁﻠﺑﺎﺕ ﺍﻟﻧﻅﺎﻡ ﺑﻛﻝ ﺗﻔﺻﻳﻼﺗﻪ ﺃﻭﻻ‬

1.6.1 UNDERSTANDING SYSTEM REQUIREMENTS

Before we write programs, we need to understand all


‫ﻗﺑﻝ ﺍﻟﺑﺩء ﻓﻲ ﺑﺭﻣﺟﺔ ﺍﻟﻧﻅﺎﻡ ﻳﺟﺏ ﺃﻥ ﻧﻔﻬﻡ ﺍﻵﻟﻳﺔ ﺍﻟﻣﺗﺑﻌﺔ ﻓﻲ‬
the details about the tasks of borrowing books. One of ‫ ﺃﻱ ﻓﻬﻡ ﺍﻟﻧﻅﺎﻡ ﺍﻟﻳﺩﻭﻱ‬،‫ﺇﻋﺎﺭﺓ ﺍﻟﻛﺗﺏ ﻣﻥ ﺍﻟﺑﺩﺍﻳﺔ ﺣﺗﻰ ﺍﻟﻧﻬﺎﻳﺔ‬
the skills required from programmers that they must be ‫ ﻭﻫﻧﺎﻟﻙ ﻁﺭﻕ ﻋﺩﻳﺩﺓ ﻓﻲ ﻋﻣﻠﻳﺔ ﺟﻣﻊ‬.‫)ﺍﻟﻭﺭﻗﻲ( ﺍﻟﺣﺎﻟﻲ‬
detail-oriented! That is to pay attention to all the details ‫ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﺍﻟﺗﻲ ﻧﺣﺗﺎﺝ ﺇﻟﻳﻬﺎ ﻣﻥ ﻋﻣﻝ ﺍﻟﻣﻘﺎﺑﻼﺕ ﻣﻊ‬
when designing and coding new programs. We need to ‫ﺍﻷﺷﺧﺎﺹ ﺍﻟﻣﻌﻧﻳﻳﻥ ﻭﻓﻲ ﺑﻌﺽ ﺍﻟﺣﺎﻻﺕ ﻻ ﺑﺩ ﻣﻥ ﻋﻣﻝ‬
gather information about the currently used system. ‫ﺍﺳﺗﺑﻳﺎﻧﺎﺕ ﺧﺎﺻﺔ ﻓﻲ ﺣﺎﻝ ﻭﺟﻭﺩ ﻋﺩﺩ ﻛﺑﻳﺭ ﻣﻥ ﺍﻟﻣﻭﻅﻔﻳﻥ‬
There are many ways to do that; for example, we need ‫ﻟﻔﻬﻡ ﺍﻵﻟﻳﺎﺕ ﺍﻟﻣﺗﻌﺑﺔ ﻓﻲ ﻋﻣﻠﻬﻡ ﻭﺍﻟﻣﺷﺎﻛﻝ ﺍﻟﺗﻲ ﺗﻭﺍﺟﻬﻬﻡ‬
‫ ﻭﻗﺩ ﻳﻛﻭﻥ ﻣﻥ ﺍﻟﻣﻔﻳﺩ ﺍﻟﺟﻠﻭﺱ ﻓﻲ ﻣﻛﺎﻥ ﺍﻟﻌﻣﻝ‬.‫ﻭﻏﻳﺭﻫﺎ‬
to conduct meetings with employees and management.
‫ﻭﻣﺷﺎﻫﺩﺓ ﺍﻟﻌﻣﻠﻳﺎﺕ ﻋﻠﻰ ﺃﺭﺽ ﺍﻟﻭﺍﻗﻊ ﻭﻛﺗﺎﺑﺔ ﺍﻟﺳﻳﻧﺎﺭﻳﻭﻫﺎﺕ‬
We may need to make up questionnaires in some cases ‫ ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺃﺧﺫ ﻧﺳﺦ ﻋﻥ ﺟﻣﻳﻊ ﺍﻟﻧﻣﺎﺫﺝ‬،‫ﺍﻟﻣﻌﻣﻭﻝ ﺑﻬﺎ‬
when we deal with large companies. We may sit down .‫ﻭﺍﻷﻭﺭﺍﻕ ﺍﻟﻣﺳﺗﺧﺩﻣﺔ ﻓﻲ ﻋﻣﻠﻳﺔ ﺍﻹﻋﺎﺭﺓ ﻭﺩﺭﺍﺳﺗﻬﺎ ﻭﺗﺣﻠﻳﻠﻬﺎ‬
and watch how things work, and then we may write ‫ﻻ ﻳﻣﻛﻧﻧﺎ ﺍﻟﺧﻭﺽ ﻓﻲ ﺟﻣﻳﻊ ﺍﻟﺗﻔﺻﻳﻼﺕ ﻫﻧﺎ ﻭﺍﻟﺗﻲ ﺗﺣﺗﺎﺝ ﺇﻟﻰ‬
scenarios and lists of operations. We may make copies ‫ﻛﺗﺏ ﻟﺷﺭﺣﻬﺎ ﺑﺎﻟﺗﻔﺻﻳﻝ ﻭﻟﻛﻥ ﺳﻧﻛﺗﻔﻲ ﺑﻌﺭﺿﻬﺎ ﺑﺻﻭﺭﺓ‬
of all the forms used in the current borrowing system, ‫ﻣﺧﺗﺻﺭﺓ ﻭﻭﺍﺿﺣﺔ ﺑﺣﻳﺙ ﺗﻣﻛﻧﻧﺎ ﻣﻥ ﺍﻟﻭﺻﻭﻝ ﺇﻟﻰ‬
which is the manual system. ‫ ﻭﻟﻔﻬﻡ ﺍﻟﻣﻁﻠﻭﺏ ﻗﻣﻧﺎ ﺑﺎﻟﺟﻠﻭﺱ ﻣﻊ ﺍﻟﻣﻭﻅﻑ‬.‫ﺍﻟﻣﻁﻠﻭﺏ‬
‫ﺍﻟﻣﺳﺅﻭﻝ ﻋﻥ ﺇﻋﺎﺭﺓ ﺍﻟﻛﺗﺏ ﻭﻁﻠﺑﻧﺎ ﻣﻧﻪ ﺳﺭﺩ ﻋﻣﻠﻳﺔ ﺍﻹﻋﺎﺭﺓ‬
To understand how the library system works, we sat
:‫ﻭﻋﻣﻠﻳﺔ ﺇﻋﺎﺩﺓ ﺍﻟﻛﺗﺏ ﺧﻁﻭﺓ ﺑﺧﻁﻭﺓ ﻭﻛﺎﻥ ﺍﻟﺭﺩ ﻛﺎﻟﺗﺎﻟﻲ‬
down with the employee and asked her to tell us in
details the steps in borrowing and returning books, :‫ ﻋﻣﻠﻳﺔ ﺇﻋﺎﺭﺓ ﺍﻟﻛﺗﺏ‬:‫ﺃﻭﻻ‬
which is as follows:
‫ﻳﺄﺗﻲ ﺍﻟﻁﺎﻟﺏ ﺇﻟﻰ ﻣﻛﺗﺏ ﺍﻹﻋﺎﺭﺓ ﻭﻣﻌﻪ ﺍﻟﻛﺗﺎﺏ ﺍﻟﺫﻱ‬ .1
I. The operation of borrowing books ‫ﻳﻧﻭﻱ ﺍﺳﺗﻌﺎﺭﺗﻪ ﻭﺍﻟﺫﻱ ﺃﺣﺿﺭﻩ ﻣﻥ ﺍﻟﺭﻑ ﺍﻟﻣﺧﺻﺹ‬
1. A student comes to the borrowing disk with the book .‫ﻟﻪ ﻓﻲ ﺍﻟﻣﻛﺗﺑﺔ‬
to borrow. ‫ﺗﺳﺗﻠﻡ ﻣﻭﻅﻔﺔ ﺍﻹﻋﺎﺭﺓ ﺍﻟﻛﺗﺎﺏ ﻣﻥ ﺍﻟﻁﺎﻟﺏ ﻭﺗﻁﻠﺏ ﻣﻧﻪ‬ .2
2. The employee takes the book and asks the student for .‫ﺃﻳﺿﺎ ﺇﺑﺭﺍﺯ ﻫﻭﻳﺗﻪ ﺍﻟﺟﺎﻣﻌﻳﺔ‬
his ID card. ‫ﺗﺳﺣﺏ ﺍﻟﻣﻭﻅﻔﺔ ﺑﻁﺎﻗﺔ ﺍﻹﻋﺎﺭﺓ ﻣﻥ ﺍﻟﻛﺗﺎﺏ ﻭﺗﺩﻭﻥ ﻋﻠﻳﻪ‬ .3
3. The employee removes the borrowing card from the ‫ﻣﻌﻠﻭﻣﺎﺕ ﺍﻟﻁﺎﻟﺏ ﺍﻟﻣﻭﺟﻭﺩﺓ ﻋﻠﻰ ﻫﻭﻳﺗﻪ ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ‬
back of the book and writes down information about .‫ﺗﺎﺭﻳﺦ ﺍﻹﻋﺎﺭﺓ ﻭﻳﺣﺗﻔﻅ ﺑﻬﺎ‬
the student and the borrowing date, and keeps the ‫ﺗﻘﻭﻡ ﺍﻟﻣﻭﻅﻔﺔ ﺑﻭﺿﻊ ﺧﺗﻡ ﺍﻟﺗﺎﺭﻳﺦ ﻋﻠﻰ ﺟﺩﻭﻝ ﻣﻠﺻﻖ‬ .4
card in a special drawer.
،‫ﻓﻲ ﺁﺧﺭ ﺻﻔﺣﺔ ﻣﻥ ﺍﻟﻛﺗﺎﺏ ﻣﺑﻳﻧﺎ ﺗﺎﺭﻳﺦ ﺍﻹﻋﺎﺭﺓ‬
4. The employee stamps the borrowing date in a table
‫ﺗﻘﻭﻡ ﺍﻟﻣﻭﻅﻔﺔ ﺑﺈﻋﺎﺩﺓ ﺍﻟﻛﺗﺎﺏ ﻟﻠﻁﺎﻟﺏ ﻭﺗﻁﻠﺏ ﻣﻥ‬ .5
placed in the inside of the back of the book.
5. The employee gives back the book to the student and ‫ ﻭﻳﻣﻛﻥ ﺗﺟﺩﻳﺩ‬،‫ﺍﻟﻁﺎﻟﺏ ﺇﻋﺎﺩﺓ ﺍﻟﻛﺗﺎﺏ ﺧﻼﻝ ﺃﺳﺑﻭﻋﻳﻥ‬
asks her to return it within two weeks. .‫ﺍﻹﻋﺎﺭﺓ ﻓﻲ ﺫﻟﻙ ﺍﻟﻭﻗﺕ‬
6. The student leaves with the book. .‫ﻳﻐﺎﺩﺭ ﺍﻟﻁﺎﻟﺏ ﺍﻟﻣﻛﺗﺏ ﻭﻣﻌﻪ ﺍﻟﻛﺗﺎﺏ ﺍﻟﻣﻌﺎﺭ‬ .6

:‫ﺛﺎﻧﻳﺎ ﻋﻣﻠﻳﺔ ﺇﻋﺎﺩﺓ ﺍﻟﻛﺗﺎﺏ‬


II. The operation of returning books
1. The student comes back with the borrowed book,
‫ ﻳﺄﺗﻲ ﺍﻟﻁﺎﻟﺏ ﻭﻣﻌﻪ ﺍﻟﻛﺗﺎﺏ ﻹﻋﺎﺩﺗﻪ ﻭﻳﻘﻭﻡ ﺑﺗﺳﻠﻳﻣﻪ‬.1
gives it to the employee and leaves. .‫ﻟﻠﻣﻭﻅﻔﺔ ﻭﻳﻐﺎﺩﺭ ﺍﻟﻣﻛﺗﺏ‬
2. The employee looks for the borrowing card that ‫ ﺗﻘﻭﻡ ﺍﻟﻣﻭﻅﻔﺔ ﺑﻔﺗﺢ ﺩﺭﺝ ﻣﺧﺻﺹ ﻭﺗﺑﺣﺙ ﻋﻥ ﺑﻁﺎﻗﺔ‬.2
belongs to the returned book in his drawer. .‫ﺍﻹﻋﺎﺭﺓ ﺍﻟﻣﺧﺻﺹ ﻟﻠﻛﺗﺎﺏ‬
3. The employee writes down the returning date on the ‫ ﺗﺩﻭﻥ ﺍﻟﻣﻭﻅﻔﺔ ﺗﺎﺭﻳﺦ ﺇﺭﺟﺎﻉ ﺍﻟﻛﺗﺎﺏ ﺍﻟﻣﻭﺟﻭﺩ ﻋﻠﻰ‬.3
card and returns it inside the book. ‫ﺍﻟﺑﻁﺎﻗﺔ ﻭﺗﻌﻳﺩﻫﺎ ﺇﻟﻰ ﺍﻟﻣﻛﺎﻥ ﺍﻟﻣﺧﺻﺹ ﺩﺍﺧﻝ ﺍﻟﻛﺗﺎﺏ‬

8
‫‪M.A. Eljinini‬‬

‫‪4. The employee then returns the book to the bookshelf‬‬ ‫‪ .4‬ﺃﻳﺿﺎ ﺗﻘﻭﻡ ﺑﺗﺩﻭﻳﻥ ﺍﻟﺗﺎﺭﻳﺦ ﻓﻲ ﺍﻟﺟﺩﻭﻝ ﻭﺍﻟﻣﻭﺟﻭﺩ ﻓﻲ‬
‫‪where it belongs.‬‬ ‫ﺁﺧﺭ ﺻﻔﺣﺔ‪ ،‬ﻭﺗﻌﻳﺩ ﺍﻟﻛﺗﺎﺏ ﺇﻟﻰ ﻣﻛﺎﻧﻪ ﺍﻟﻣﺧﺻﺹ ﻋﻠﻰ‬
‫‪After that, we asked the employee about other‬‬ ‫ﺍﻟﺭﻑ ﻹﻋﺎﺭﺗﻪ ﻣﻥ ﺟﺩﻳﺩ‪.‬‬
‫‪operations and problems that she faces during her‬‬
‫ﺑﻌﺩ ﺫﻟﻙ ﺳﺄﻟﻧﺎ ﺍﻟﻣﻭﻅﻔﺔ ﺇﻥ ﻛﺎﻧﺕ ﻫﻧﺎﻟﻙ ﺇﺟﺭﺍءﺍﺕ ﺃﺧﺭﻯ ﺗﻘﻭﻡ‬
‫‪work. She mentioned that students after graduation‬‬ ‫ﺑﻬﺎ ﻓﻲ ﻋﻣﻠﻬﺎ‪ ،‬ﻭﺃﻳﺿﺎ ﻋﻥ ﺍﻟﺻﻌﺎﺏ ﻭﺍﻟﻣﺷﺎﻛﻝ ﺍﻟﺗﻲ ﺗﻭﺍﺟﻬﻬﺎ‪.‬‬
‫‪comes back to the library to sign a quittance form. In‬‬ ‫ﻓﺫﻛﺭﺕ ﻟﻧﺎ ﺃﻥ ﺍﻟﻁﺎﻟﺏ ﻓﻲ ﻣﺭﺣﻠﺔ ﺍﻟﺗﺧﺭﺝ ﻳﻁﻠﺏ ﺑﺭﺍءﺓ ﺫﻣﺗﻪ‬
‫‪this case, the employee must search all cards in the‬‬ ‫ﻣﻥ ﺍﻟﻣﻛﺗﺑﺔ‪ ،‬ﻭﻫﻧﺎ ﻻ ﺑﺩ ﻣﻥ ﺇﺟﺭﺍء ﻋﻣﻠﻳﺔ ﺑﺣﺙ ﻟﻠﺗﺄﻛﺩ ﻣﻥ ﺃﻥ‬
‫‪drawer to ensure that the student has returned all‬‬ ‫ﺍﻟﻁﺎﻟﺏ ﻗﺎﻡ ﺑﺈﻋﺎﺩﺓ ﺟﻣﻳﻊ ﺍﻟﻛﺗﺏ ﺍﻟﺗﻲ ﺍﺳﺗﻌﺎﺭﻫﺎ‪ .‬ﻭﻗﺩ ﻳﻁﻠﺏ‬
‫‪borrowed books. Another problem is that the manager‬‬ ‫ﻣﺩﻳﺭ ﺍﻟﻣﻛﺗﺑﺔ ﻣﻥ ﺍﻟﻣﻭﻅﻔﺔ ﺇﻋﺩﺍﺩ ﺗﻘﺭﻳﺭ ﺑﺎﻟﻛﺗﺏ ﺍﻟﻣﺗﺄﺧﺭﺓ‬
‫‪may ask her to prepare a report showing all the late‬‬ ‫ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺗﻘﺎﺭﻳﺭ ﺃﺧﺭﻯ ﻭﺍﻟﺗﻲ ﺗﻌﺗﺑﺭ ﻣﻥ ﺍﻟﻌﻣﻠﻳﺎﺕ‬
‫ﺍﻟﻣﺿﻧﻳﺔ ﻳﺩﻭﻳﺎ ﻭﺍﻟﻣﻌﺭﺿﺔ ﻟﻸﺧﻁﺎء ﺍﻟﺑﺷﺭﻳﺔ‪ .‬ﻣﻥ ﻫﻧﺎ ﻧﺭﻯ‬
‫‪books. All these operations are subject to human errors.‬‬ ‫ﺃﻫﻣﻳﺔ ﺣﻭﺳﺑﺔ ﻫﺫﻩ ﺍﻷﻧﻅﻣﺔ ﻭﺍﻟﺗﻲ ﺗﺳﺎﻋﺩ ﻓﻲ ﺍﻟﻘﺿﺎء ﻋﻠﻰ‬
‫‪Some of these operations require hard work and may‬‬ ‫ﺍﻷﺧﻁﺎء ﺍﻟﺑﺷﺭﻳﺔ ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺗﻘﻠﻳﻝ ﺍﻟﻭﻗﺕ ﻭﺍﻟﺟﻬﺩ ﻓﻲ‬
‫‪take a long time to achieve. Paper forms may be‬‬ ‫ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﻣﻁﻠﻭﺑﺔ ﺑﺷﻛﻝ ﻛﺑﻳﺭ ﻭﻓﺎﻋﻝ‪ .‬ﺇﻥ ﻫﺫﻩ ﺍﻷﻧﻅﻣﺔ‬
‫‪misplaced or lost. Computer applications help us‬‬ ‫ﺍﻟﺣﺎﺳﻭﺑﻳﺔ ﺗﻌﻣﻝ ﻋﻠﻰ ﻣﻌﺎﻟﺟﺔ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻣﻥ ﺗﺧﺯﻳﻧﻬﺎ‬
‫‪bypass all these problems. They can accomplish tasks‬‬ ‫ﻭﺍﺳﺗﻌﺎﺩﺗﻬﺎ ﻭﻋﺭﺿﻬﺎ ﺑﺷﻛﻝ ﺃﻭ ﺑﺂﺧﺭ ﻭﺑﺷﻛﻝ ﺳﺭﻳﻊ ﻭﺩﻗﻳﻖ‬
‫‪easy and super-fast.‬‬ ‫ﺟﺩﺍ‪.‬‬

‫‪1.6.2 SYSTEM ANALYSIS‬‬

‫‪Computers are mostly about processing data‬‬ ‫ﻳﻣﻛﻥ ﺍﻻﺳﺗﻧﺗﺎﺝ ﻣﻣﺎ ﺳﺑﻖ ﺃﻥ ﻫﻧﺎﻟﻙ ﺧﻁﻭﺍﺕ ﻣﻌﻳﻧﻪ ﻗﺎﻣﺕ ﺑﻬﺎ‬
‫‪and turning it into useful information. From‬‬ ‫ﺍﻟﻣﻭﻅﻔﺔ ﻋﻧﺩ ﺇﻋﺎﺭﺓ ﺍﻟﻛﺗﺎﺏ ﻭﺍﺳﺗﺭﺟﺎﻋﻪ‪ ،‬ﻭﺃﻳﺿﺎ ﻫﻧﺎﻟﻙ ﻣﻌﻠﻭﻣﺎﺕ‬
‫‪observing the above operations, we have‬‬ ‫ﻣﻌﻳﻧﻪ ﺗﻡ ﺗﺩﺍﻭﻟﻬﺎ ﻭﺗﺩﻭﻳﻧﻬﺎ ﺧﻼﻝ ﺍﻟﻌﻣﻠﻳﺗﻳﻥ‪ ،‬ﻭﻫﺫﻩ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻫﻲ‪:‬‬
‫‪noticed that there is some information that has‬‬
‫‪been written down and kept, such as:‬‬ ‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺍﻟﻁﺎﻟﺏ )ﺍﺳﻡ ﺍﻟﻁﺎﻟﺏ ﻭﺭﻗﻣﻪ ﺍﻟﺟﺎﻣﻌﻲ(‬
‫‪-‬‬ ‫‪Information about the student (Student name‬‬ ‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺍﻟﻛﺗﺎﺏ )ﻋﻧﻭﺍﻥ ﺍﻟﻛﺗﺎﺏ ﻭﺭﻗﻣﻪ(‬
‫)‪and number‬‬ ‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺣﺩﺙ ﺍﻹﻋﺎﺭﺓ )ﺍﻟﻁﺎﻟﺏ ﺍﻟﻣﺳﺗﻌﻳﺭ‪ ،‬ﺍﻟﻛﺗﺎﺏ ﺍﻟﻣﻌﺎﺭ‪،‬‬
‫ﻭﺗﺎﺭﻳﺦ ﺍﻹﻋﺎﺭﺓ(‬
‫‪-‬‬ ‫‪Information about the book (Book type and‬‬
‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺣﺩﺙ ﺍﻹﻋﺎﺩﺓ )ﺍﺳﻡ ﺍﻟﻁﺎﻟﺏ ﺍﻟﺫﻱ ﺃﻋﺎﺩ ﺍﻟﻛﺗﺎﺏ‪،‬‬
‫)‪number‬‬
‫ﻋﻧﻭﺍﻥ ﺍﻟﻛﺗﺎﺏ ﺍﻟﺗﻲ ﺗﻣﺕ ﺇﻋﺎﺩﺗﻪ‪ ،‬ﻭﺗﺎﺭﻳﺦ ﺇﻋﺎﺩﺓ ﺍﻟﻛﺗﺎﺏ(‬
‫‪-‬‬ ‫‪Information about the borrowing task‬‬
‫)‪(Student, Book, Borrowing Date‬‬ ‫ﺃﻣﺎ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﺍﻟﻣﻁﻠﻭﺑﺔ ﻋﻧﺩ ﻋﻣﻠﻳﺔ ﺍﻟﺑﺣﺙ ﻓﻬﻲ‪:‬‬
‫‪-‬‬ ‫‪Information about the returning task‬‬
‫)‪(Student, Book, Returning Date‬‬ ‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺍﻟﻛﺗﺏ ﺍﻟﻣﻌﺎﺭﺓ ﻟﻁﺎﻟﺏ ﻣﻌﻳﻥ‬
‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﺍﻟﻛﺗﺏ ﺍﻟﻣﺗﺄﺧﺭﺓ‬
‫‪Information needed when performing a search:‬‬ ‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﻋﻥ ﻛﺗﺎﺏ ﻣﻌﻳﻥ ﻟﻣﻌﺭﻓﺔ ﺇﻥ ﻛﺎﻥ ﺍﻟﻛﺗﺎﺏ ﻣﻌﺎﺭ ﺃﻡ ﻏﻳﺭ‬
‫ﻣﻌﺎﺭ‬
‫‪-‬‬ ‫‪Information about the borrowed book‬‬
‫‪ -‬ﻣﻌﻠﻭﻣﺎﺕ ﺃﺧﺭﻯ ﻗﺩ ﻳﺣﺗﺎﺝ ﺇﻟﻳﻬﺎ ﺍﻟﻣﺩﻳﺭ ﻣﻥ ﺗﻘﺎﺭﻳﺭ ﻭﻏﻳﺭﻫﺎ‬
‫‪-‬‬ ‫‪Information about late books‬‬
‫‪-‬‬ ‫‪Information about the status of a specific‬‬ ‫ﺇﺫﺍ ﻫﻧﺎﻟﻙ ﺃﺭﺑﻊ ﻋﻣﻠﻳﺎﺕ ﺭﺋﻳﺳﻳﺔ ﺗﻘﻭﻡ ﺑﻬﺎ ﺍﻟﻣﻭﻅﻔﺔ ﻭﻫﻲ‪:‬‬
‫‪book‬‬
‫‪-‬‬ ‫‪Other reports for management.‬‬ ‫ﺇﻋﺎﺭﺓ ﻛﺗﺎﺏ‬ ‫‪.1‬‬
‫ﺇﻋﺎﺩﺓ ﻛﺗﺎﺏ‬ ‫‪.2‬‬
‫‪There are four main tasks that the employee‬‬ ‫ﻋﻣﻠﻳﺎﺕ ﺍﻟﺑﺣﺙ‬ ‫‪.3‬‬
‫‪does:‬‬ ‫ﺇﻋﺩﺍﺩ ﺍﻟﺗﻘﺎﺭﻳﺭ )ﻣﺛﻼ‪ :‬ﻁﺑﺎﻋﺔ ﻗﺎﺋﻣﺔ ﺑﺄﺳﻣﺎء ﺍﻟﻛﺗﺏ ﺍﻟﻣﻌﺎﺭﺓ(‬ ‫‪.4‬‬
‫‪1.‬‬ ‫‪Borrowing Book‬‬ ‫ﻭﺍﻵﻥ ﻧﺣﺗﺎﺝ ﻓﻲ ﻫﺫﻩ ﺍﻟﻣﺭﺣﻠﺔ ﺇﻟﻰ ﺇﻋﺩﺍﺩ ﺭﺳﻭﻣﺎﺕ ﺗﺑﻳﻥ ﺍﻧﺳﻳﺎﺏ‬
‫‪2.‬‬ ‫‪Returning Book‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺣﺎﻟﻲ ﻭﺗﺳﺎﻋﺩ ﺍﻟﻣﺑﺭﻣﺞ ﻓﻲ ﺗﺻﻣﻳﻡ ﺍﻟﻧﻅﺎﻡ‬
‫‪3.‬‬ ‫‪Searching for Books‬‬ ‫ﺍﻟﺟﺩﻳﺩ‪ .‬ﺇﻥ ﺍﻟﺷﻛﻝ ‪ 4-1‬ﻳﺑﻳﻥ ﻋﻣﻠﻳﺎﺕ ﺇﻋﺎﺭﺓ ﻛﺗﺎﺏ ﻭﻛﻣﺎ ﺷﺭﺣﺗﻬﺎ‬
‫‪4.‬‬ ‫‪Producing Reports (i.e., printing lists of‬‬ ‫ﺍﻟﻣﻭﻅﻔﺔ‪ ،‬ﻓﺎﻟﺩﻭﺍﺋﺭ ﺗﺑﻳﻥ ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﺗﻲ ﻗﺎﻣﺕ ﺑﻬﺎ ﻭﺍﻟﻣﺳﺗﻁﻳﻼﺕ‬
‫ﺗﺑﻳﻥ ﻣﺩﺧﻼﺕ ﻭﻣﺧﺭﺟﺎﺕ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﺍﻷﺳﻬﻡ ﺍﻟﺭﻓﻳﻌﺔ ﺗﺑﻳﻥ ﺍﻧﺳﻳﺎﺏ‬

‫‪9‬‬
Practical Data Structures with C++, C#, and Java

books) .‫ ﻭﺃﻣﺎ ﺍﻷﺳﻬﻡ ﺍﻟﻐﻠﻳﻅﺔ ﺗﺑﻳﻳﻥ ﺗﺳﻠﺳﻝ ﺍﻟﻌﻣﻠﻳﺎﺕ‬،‫ﺍﻟﺑﻳﺎﻧﺎﺕ‬

At this stage, we need to prepare some drawings ‫ ﻋﻣﻠﻳﺎﺕ ﺇﻋﺎﺩﺓ ﻛﺗﺎﺏ ﻭﺃﻳﺿﺎ ﻛﻣﺎ ﺷﺭﺣﺗﻬﺎ‬5-1 ‫ﻛﻣﺎ ﻳﺑﻳﻥ ﺍﻟﺷﻛﻝ‬
that show data flows in the current system. Such .‫ﺍﻟﻣﻭﻅﻔﺔ‬
diagrams are called Data Flow Diagrams (DFD),
which provide great help to programmers when .‫ﻭﺳﻧﺗﺭﻙ ﺍﻟﺭﺳﻭﻡ ﺍﻟﺗﻲ ﺗﺑﻳﻥ ﻋﻣﻠﻳﺎﺕ ﺍﻟﺑﺣﺙ ﻛﺗﻣﺭﻳﻥ ﻟﻠﻁﺎﻟﺏ‬
designing the new system. Figure 1-4 shows
the tasks of borrowing books, which we
explained in the previous section. Circles show
tasks, and rectangles are for input and output
operations, while arrows show the flow of data.

Figure 1-5: Returning Book

Figure 1-4: Borrow Book


Figure 1-5 shows the tasks of returning books,
as explained by the library employee.
‫ﻓﻲ ﻧﻬﺎﻳﺔ ﻫﺫﻩ ﺍﻟﻣﺭﺣﻠﺔ ﻳﻘﻭﻡ ﺍﻟﻣﺑﺭﻣﺞ )ﺃﻭ ﻣﺣﻠﻝ ﺍﻟﻧﻅﻡ( ﺑﻌﻣﻝ ﺩﺭﺍﺳﺔ‬
At the end of this part, the programmer (or ‫ ﻫﻝ ﺣﻭﺳﺑﺔ ﺍﻟﻧﻅﺎﻡ ﻣﺟﺩﻳﺔ ﺍﻗﺗﺻﺎﺩﻳﺎ؟ ﻭﻫﻧﺎ ﻻ ﺑﺩ ﻣﻥ‬،‫ﺍﻟﺟﺩﻭﻯ ﺃﻳﺿﺎ‬
system analyst) conduct a feasibility study. ‫ﺩﺭﺍﺳﺔ ﺗﻛﻠﻔﺔ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ ﻭﻫﺫﺍ ﻳﺷﻣﻝ ﻛﻝ ﻣﺎ ﻳﺣﺗﺎﺟﻪ ﺍﻟﻧﻅﺎﻡ ﻣﻥ‬
Is it worth it financially to have a computer .‫ﺃﺟﻬﺯﺓ ﺣﺎﺳﻭﺏ ﻭﺑﺭﻣﺟﻳﺎﺕ ﺟﺎﻫﺯﺓ ﻣﻥ ﻧﻅﻡ ﺗﺷﻐﻳﻝ ﻭﻏﻳﺭﻫﺎ‬
program to do the work? To answer this
question, we need to find out the cost of the new ‫ﻓﻲ ﺑﻌﺽ ﺍﻷﻧﻅﻣﺔ ﺍﻟﻛﺑﻳﺭﺓ ﻗﺩ ﻳﻛﻭﻥ ﻫﻧﺎﻟﻙ ﻋﺩﺩ ﻛﺑﻳﺭ ﻣﻥ ﺍﻟﺣﺎﺳﺑﺎﺕ‬
system, including hardware and software. In ‫ﺍﻟﻣﺗﺻﻠﺔ ﻋﻥ ﻁﺭﻳﻖ ﺍﻟﺷﺑﻛﺎﺕ ﺍﻟﺣﺎﺳﻭﺑﻳﺔ ﻭﺍﻟﺗﻲ ﺗﺣﺗﺎﺝ ﺇﻟﻰ ﺣﺳﺎﺏ‬
some cases, where computers placed inside ‫ ﻭﺃﻳﺿﺎ ﻓﻲ ﺍﻟﻧﻬﺎﻳﺔ ﻻ ﺑﺩ ﻣﻥ ﺣﺳﺎﺏ ﺗﻛﻠﻔﺔ ﺇﻧﺗﺎﺝ‬،‫ﺩﻗﻳﻖ ﻟﺗﻛﻠﻔﺗﻬﺎ‬
many offices, we may need to consider computer ‫ﺍﻟﺑﺭﻧﺎﻣﺞ ﺍﻟﺟﺩﻳﺩ ﻭﺍﻟﺫﻱ ﻳﺷﻣﻝ ﻋﺩﺩ ﺍﻟﺳﺎﻋﺎﺕ ﺍﻟﺗﻲ ﻳﺣﺗﺎﺟﻬﺎ ﺍﻟﻣﺑﺭﻣﺞ‬
networking to connect these computers. .‫ﻹﻧﺗﺎﺟﻪ ﻭﺗﻛﻠﻔﺔ ﺍﻟﺳﺎﻋﺔ ﻭﻏﻳﺭﻫﺎ‬
Moreover, we need to determine the cost of the
new application. For example, how many hours ‫ﻭﻋﺎﺩﺓ ﻳﻧﻅﺭ ﺍﻟﻣﺑﺭﻣﺞ ﺇﻟﻰ ﺍﻟﺑﺩﺍﺋﻝ ﻟﻳﺭﻯ ﺃﻳﻬﺎ ﺃﻓﺿﻝ ﻟﻳﻘﺩﻣﻬﺎ ﻓﻲ‬
it takes to produce the complete system. ‫ﺗﻘﺭﻳﺭ ﻣﻔﺻﻝ ﻟﻠﻣﺩﻳﺭ ﻣﻊ ﺗﻭﺻﻳﺔ ﺑﺎﺧﺗﻳﺎﺭ ﺍﺣﺩﺍﻫﺎ ﻭﺍﻻﺳﺗﻣﺭﺍﺭﻳﺔ ﺃﻡ‬
A table with several alternatives should be ‫ ﻟﻥ ﻧﺧﻭﺽ ﻓﻲ ﻫﺫﻩ ﺍﻟﺗﻔﺎﺻﻳﻝ ﻫﻧﺎ‬.‫ﺍﻟﺑﻘﺎء ﻋﻠﻰ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺣﺎﻟﻲ‬
prepared and given to the management with a ‫ ﺃﻱ ﻧﻅﺎﻡ ﺇﻋﺎﺭﺓ‬،‫ﻭﺳﻧﻛﺗﻔﻲ ﺑﺎﻟﻘﻭﻝ ﺇﻥ ﺣﻭﺳﺑﺔ ﻫﺫﺍ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺑﺳﻳﻁ‬
recommendation. Shall we proceed with the .‫ ﻣﺟﺩﻱ ﻟﻠﻘﻳﺎﻡ ﺑﻪ ﻭﺇﻋﺩﺍﺩﻩ ﻣﻥ ﻗﺑﻝ ﺍﻟﻣﺑﺭﻣﺞ‬،‫ﺍﻟﻛﺗﺏ‬
system or go with other alternatives? Since this
is a simple application, we shall proceed to the
next part.

10
M.A. Eljinini

1.6.3 DESIGNING THE NEW SYSTEM

At this stage, we shall design the input screens for the new ‫ﻓﻲ ﻫﺫﻩ ﺍﻟﻣﺭﺣﻠﺔ ﻳﻘﻭﻡ ﺍﻟﻣﺑﺭﻣﺞ ﺑﺗﺻﻣﻳﻡ ﺷﺎﺷﺎﺕ ﺍﻟﻧﻅﺎﻡ‬
system. These screens must automate reality! We need ‫ ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﺗﺻﻣﻳﻡ ﺍﻟﻣﻠﻔﺎﺕ‬،‫ﻭﺍﻟﺗﻲ ﺗﺣﺎﻛﻲ ﺍﻟﻭﺍﻗﻊ‬
to design reports, output screens, and the data storage of ‫ﺍﻟﺗﻲ ﻳﺣﺗﺎﺟﻬﺎ ﺍﻟﻧﻅﺎﻡ ﻟﺗﺧﺯﻳﻥ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻭﺃﻳﺿﺎ ﺗﺻﻣﻳﻡ‬
files for storing data. Another important task that we need ‫ ﻭﻣﻥ ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻟﻣﻬﻣﺔ ﻓﻲ ﻫﺫﻩ‬.‫ﺍﻟﺗﻘﺎﺭﻳﺭ ﺍﻟﻣﻁﻠﻭﺑﺔ‬
to consider is designing the algorithm for each task, such ‫ﺍﻟﻣﺭﺣﻠﺔ ﺗﺻﻣﻳﻡ ﺍﻟﺧﻭﺍﺭﺯﻣﻳﺎﺕ ﻟﻣﻌﺎﻟﺟﺔ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ‬
as borrowing books and returning books. Usually, ‫ﻣﺭﺍﺣﻠﻬﺎ ﺍﻟﻣﺧﺗﻠﻔﺔ ﻣﻥ ﻋﻣﻠﻳﺎﺕ ﺍﻟﺑﺣﺙ ﻭﺍﻟﻌﻣﻠﻳﺎﺕ‬
programmers use diagrams to help them with the design of ‫ ﻭﻋﺎﺩﺓ‬،‫ﺍﻟﺣﺳﺎﺑﻳﺔ ﺇﻥ ﻭﺟﺩﺕ ﻭﻏﻳﺭﻫﺎ ﻣﻥ ﺍﻟﻌﻣﻠﻳﺎﺕ‬
algorithms. Now, we shall present the main algorithm, as ‫ﻳﺳﺗﻌﻳﻥ ﺑﺎﻟﺭﺳﻭﻣﺎﺕ ﺍﻟﺗﻲ ﻋﺭﺿﻧﺎﻫﺎ ﻓﻲ ﺍﻟﺟﺯء ﺍﻟﺳﺎﺑﻖ‬
follows: ‫ ﻭﻫﻧﺎ‬.‫ﻭﺍﻟﺗﻲ ﺗﺑﻳﻥ ﺍﻧﺳﻳﺎﺏ ﺍﻟﺑﻳﺎﻧﺎﺕ ﻓﻲ ﺍﻟﻧﻅﺎﻡ ﺍﻟﻳﺩﻭﻱ‬
‫ﺳﻭﻑ ﻧﻌﺭﺽ ﺍﻟﺧﻭﺍﺭﺯﻣﻳﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ ﻭﺍﻟﺗﻲ ﺗﻌﻣﻝ ﻋﻧﺩ‬
:‫ﺗﺷﻐﻳﻝ ﺍﻟﻧﻅﺎﻡ ﺍﻟﺟﺩﻳﺩ ﻭﺗﻛﻭﻥ ﻛﺎﻟﺗﺎﻟﻲ‬
1. Display the main menu on the screen, which contains
three options (borrow a book, return the book, and ‫ﺇﻅﻬﺎﺭ ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ ﻭﺍﻟﺗﻲ ﺗﺣﺗﻭﻱ ﻋﻠﻰ‬ .1
search for the book), in addition to a fourth option, ،‫ ﺇﻋﺎﺩﺓ ﻛﺗﺎﺏ‬،‫ﺍﻟﺧﻳﺎﺭﺍﺕ ﺍﻟﺛﻼﺙ )ﺍﻋﺎﺭﺓ ﻛﺗﺎﺏ‬
which is to exit from the system. When we code our ‫ﻭﺍﻟﺑﺣﺙ( ﺑﺎﻹﺿﺎﻓﺔ ﻟﺧﻳﺎﺭ ﺭﺍﺑﻊ ﻭﻫﻭ ﺍﻟﺧﺭﻭﺝ‬
program, we place the commands to display the main ‫ ﺑﺭﻣﺟﻳﺎ ﺗﻭﺿﻊ ﺃﻭﺍﻣﺭ ﺇﻅﻬﺎﺭ ﺍﻟﻘﺎﺋﻣﺔ‬.‫ﻣﻥ ﺍﻟﻧﻅﺎﻡ‬
menu inside a method (method MainMenu), which is ‫( ﻭﺍﻟﺗﻲ ﻳﺗﻡ‬MainMenu) ‫ﺍﻟﺭﺋﻳﺳﻳﺔ ﺑﺩﺍﻟﺔ‬
called whenever the system needs to show the main .‫ﺍﺳﺗﺩﻋﺎﺋﻬﺎ ﻛﻠﻣﺎ ﺍﺣﺗﺎﺝ ﺍﻟﻧﻅﺎﻡ ﺇﻟﻰ ﺇﻅﻬﺎﺭﻫﺎ‬
menu. ‫ﺍﻟﻁﻠﺏ ﻣﻥ ﺍﻟﻣﺳﺗﺧﺩﻡ )ﺍﻟﻣﻭﻅﻑ( ﺍﺧﺗﻳﺎﺭ ﺇﺣﺩﻯ‬ .2
2. The user (employee) chooses one of these four ‫ ﻭﺫﻟﻙ ﺣﺳﺏ ﺍﻟﻣﻁﻠﻭﺏ‬،‫ﻫﺫﻩ ﺍﻟﻌﻣﻠﻳﺎﺕ ﺍﻷﺭﺑﻌﺔ‬
options, according to the required task at that moment. .‫ﻣﻧﻪ ﻓﻲ ﺗﻠﻙ ﺍﻟﻠﺣﻅﺔ‬
3. In the case of choosing, borrow a book: Go to the ‫ ﺍﻻﻧﺗﻘﺎﻝ ﺇﻟﻰ ﻋﻣﻠﻳﺔ‬:‫ﻓﻲ ﺣﺎﻝ ﺍﺧﺗﻳﺎﺭ ﺍﻋﺎﺭﺓ ﻛﺗﺎﺏ‬ .3
borrowing process by calling the borrowing method ‫ﺍﻹﻋﺎﺭﺓ‬ ‫ﺩﺍﻟﺔ‬ ‫ﺑﺎﺳﺗﺩﻋﺎء‬ ‫ﺍﻹﻋﺎﺭﺓ‬
(Method BorrowBook). Return to the main menu after ‫ ﻭﺑﻌﺩ ﺍﻻﻧﺗﻬﺎء ﻣﻧﻬﺎ ﻳﺗﻡ‬،(BorrowBook)
.‫ﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
completion of the borrowing task.
‫ ﺍﻻﻧﺗﻘﺎﻝ ﺇﻟﻰ ﻋﻣﻠﻳﺔ‬:‫ﻓﻲ ﺣﺎﻝ ﺍﺧﺗﻳﺎﺭ ﺇﻋﺎﺩﺓ ﻛﺗﺎﺏ‬ .4
4. In the case of choosing to return the book: Go to the
‫ﺩﺍﻟﺔ‬ ‫ﺑﺎﺳﺗﺩﻋﺎء‬ ‫ﻭﺫﻟﻙ‬ ‫ﺍﻹﻋﺎﺩﺓ‬
returning book process by calling the returning book
‫ ﻭﺑﻌﺩ ﺍﻻﻧﺗﻬﺎء‬،(ReturnBook) ‫ﺍﻹﻋﺎﺩﺓ‬
method (Method ReturnBook), Return to the main .‫ﻣﻧﻬﺎ ﻳﺗﻡ ﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
menu after completion of the returning task. ‫ ﺍﻻﻧﺗﻘﺎﻝ ﺇﻟﻰ ﻋﻣﻠﻳﺎﺕ‬:‫ﻓﻲ ﺣﺎﻝ ﺍﺧﺗﻳﺎﺭ ﺍﻟﺑﺣﺙ‬ .5
5. In the case of choosing to search for a book: Go to the ‫ﺍﻟﺑﺣﺙ ﺍﻟﻣﻁﻠﻭﺑﺔ ﻭﺃﻳﺿﺎ ﻋﻥ ﻁﺭﻳﻖ ﺍﺳﺗﺩﻋﺎء‬
searching process by calling the searching method ‫ ﻭﺑﻌﺩ ﺍﻻﻧﺗﻬﺎء ﻣﻧﻬﺎ ﻳﺗﻡ‬،‫ﺍﻟﺩﺍﻟﺔ ﺍﻟﺧﺎﺻﺔ ﺑﻬﺎ‬
(Method SearchBook), Return to the main menu after .‫ﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
completion of the searching task. ‫ ﺍﻻﻧﺗﻘﺎﻝ‬:‫ﻓﻲ ﺣﺎﻝ ﺍﺧﺗﻳﺎﺭ ﺍﻟﺧﺭﻭﺝ ﻣﻥ ﺍﻟﻧﻅﺎﻡ‬ .6
6. If we choose to get out of the system, then we select ‫ﺇﻟﻰ ﻋﻣﻠﻳﺎﺕ ﺍﻟﺧﺭﻭﺝ ﻣﻥ ﺍﻟﻧﻅﺎﻡ ﻭﻣﻥ ﺛﻡ‬
Exit. .‫ﺍﻟﺧﺭﻭﺝ ﻣﻥ ﺍﻟﻧﻅﺎﻡ‬

Figure 1-6 shows the main algorithm to the system as ‫ ﺍﻟﺗﺎﻟﻲ ﻳﺑﻳﻥ ﺍﻟﺧﻭﺍﺭﺯﻣﻳﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬6-1 ‫ﺍﻟﺷﻛﻝ‬
explained above. .‫ ﻭﻛﻣﺎ ﺗﻡ ﺷﺭﺣﻪ ﻓﻲ ﺍﻷﻋﻠﻰ‬،.‫ﻟﻠﻧﻅﺎﻡ‬

11
Practical Data Structures with C++, C#, and Java

Figure 1-6: The Main Algorithm

Looking very carefully at figure 1-6, we notice there is a


loop. At the end of each method, the system returns to the ‫ﻣﻣﺎ ﺳﺑﻖ ﻧﻼﺣﻅ ﺃﻥ ﻫﻧﺎﻟﻙ ﻋﻣﻠﻳﺔ ﺗﻛﺭﺍﺭ ﻭﺍﻟﺗﻲ ﺗﻌﻳﺩﻧﺎ‬
start showing the main menu again. ‫ ﺑﺎﻹﺿﺎﻓﺔ ﺇﻟﻰ ﻋﺩﺩ ﻣﻥ‬،‫ﻛﻝ ﻣﺭﺓ ﺇﻟﻰ ﺍﻟﺷﺎﺷﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
‫ﻋﻣﻠﻳﺎﺕ ﺍﻻﺧﺗﻳﺎﺭ ﻭﺍﻟﺗﻲ ﺗﻧﻘﻠﻧﺎ ﺇﻟﻰ ﺍﻟﻌﻣﻠﻳﺔ ﺍﻟﻣﻁﻠﻭﺑﺔ‬
Figure 1-7 shows the screen for the main menu. 7-1 ‫ ﻭﻳﺑﻳﻥ ﺍﻟﺷﻛﻝ‬.‫ﻗﺑﻝ ﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺍﻟﺷﺎﺷﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬
. .‫ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‬

My Books Library ‫( ﺍﻟﺧﻳﺎﺭ ﺍﻷﻭﻝ ﻓﻲ ﺍﻟﻘﺎﺋﻣﺔ ﻭﻫﻭ ﺍﺳﺗﻌﺎﺭﺓ‬1) ‫ﻋﻧﺩ ﺇﺩﺧﺎﻝ‬


Main Menu ‫ﻛﺗﺎﺏ ﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﺎﺳﺗﺩﻋﺎء ﺩﺍﻟﺔ ﺍﻹﻋﺎﺭﺓ ﻭﺍﻟﺗﻲ ﺗﻘﻭﻡ‬
.8-1 ‫ﺑﻌﺭﺽ ﺷﺎﺷﺔ ﺍﻹﻋﺎﺭﺓ ﻛﻣﺎ ﻓﻲ ﺍﻟﺷﻛﻝ‬
1. Borrow Book
2. Return Book My Books Library
3. Search Return Book
4. Exit
Enter Book ID: ________
Enter your choice (1-4): _

Student Name:
Figure 1-7: The Main Menu
XXXXXXXXXXXX
When entering (1), the first choice in the menu, the program
calls the method for borrowing books, which in turn displays Book Title: XXXXXXXXXXXX
the “Borrow Book” screen, as shown in figure 1-8.

Correct? (Y/N) ___

Figure 1-9: Return Book Screen


12
‫‪M.A. Eljinini‬‬

‫‪My Books Library‬‬


‫‪Borrow Book‬‬ ‫ﻣﻥ ﻫﺫﺍ ﺍﻟﺷﻛﻝ ﻳﻁﻠﺏ ﺍﻟﻧﻅﺎﻡ ﺇﺩﺧﺎﻝ ﺭﻗﻡ ﺍﻟﻁﺎﻟﺏ ﻭﺭﻗﻡ‬
‫_______ ‪Enter Student ID:‬‬ ‫ﺍﻟﻛﺗﺎﺏ )ﺍﻟﺟﺯء ﺑﺎﻟﻠﻭﻥ ﺍﻷﺣﻣﺭ( ﺛﻡ ﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﺎﻟﺑﺣﺙ‬
‫ﻋﻥ ﺍﺳﻡ ﺍﻟﻁﺎﻟﺏ ﻓﻲ ﻗﺎﺋﻣﺔ ﺍﻟﻁﻠﺑﺔ ﻭﺍﻟﺑﺣﺙ ﻋﻥ ﻋﻧﻭﺍﻥ‬
‫ﺍﻟﻛﺗﺎﺏ ﻓﻲ ﻗﺎﺋﻣﺔ ﺍﻟﻛﺗﺏ ﻭﻳﻌﺭﺽ ﺍﺳﻡ ﺍﻟﻁﺎﻟﺏ ﻭﻋﻧﻭﺍﻥ‬
‫________ ‪Enter Book ID:‬‬ ‫ﺍﻟﻛﺗﺎﺏ )ﺍﻟﺟﺯء ﺑﺎﻟﻠﻭﻥ ﺍﻷﺧﺿﺭ( ﻭﺑﻌﺩ ﺫﻟﻙ ﻳﻁﻠﺏ ﻣﻥ‬
‫ﺍﻟﻣﺳﺗﺧﺩﻡ ﺍﻟﺗﺄﻛﺩ ﻣﻥ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ )ﺃﻳﺿﺎ ﺑﺎﻟﻠﻭﻥ‬
‫ﺍﻷﺣﻣﺭ( ﻭﻓﻲ ﺣﺎﻝ ﺍﻟﺗﺄﻛﺩ ﻳﻘﻭﻡ ﺍﻟﻣﺳﺗﺧﺩﻡ ﺑﺈﺩﺧﺎﻝ‬
‫‪Student Name:‬‬ ‫ﺍﻟﺣﺭﻑ )‪ (Y‬ﻟﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﻌﻣﻠﻳﺔ ﺍﻹﻋﺎﺭﺓ ﻛﺣﻔﻅ ﺭﻗﻡ‬
‫ﺍﻟﻁﺎﻟﺏ ﻓﻲ ﺍﻟﺳﺟﻝ ﺍﻟﻣﺧﺻﺹ ﻟﻠﻛﺗﺎﺏ ﻓﻲ ﻗﺎﺋﻣﺔ ﺍﻟﻛﺗﺏ‬
‫‪XXXXXXXXXXXX‬‬ ‫ﻟﻠﺗﺄﻛﻳﺩ ﺃﻥ ﺍﻟﻛﺗﺎﺏ ﻣﻌﺎﺭ‪ ،‬ﺛﻡ ﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺷﺎﺷﺔ ﺍﻟﻘﺎﺋﻣﺔ‬
‫ﺍﻟﺭﺋﻳﺳﻳﺔ‪ .‬ﺃﻣﺎ ﻓﻲ ﺣﺎﻟﺔ ﺃﺩﺧﻝ ﺍﻟﻣﺳﺗﺧﺩﻡ ﺍﻟﺣﺭﻑ )‪(N‬‬
‫‪Figure 1-8: Borrow Book Screen‬‬ ‫ﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﺈﻟﻐﺎء ﺍﻟﻌﻣﻠﻳﺔ ﻭﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ ﺍﻟﻘﺎﺋﻣﺔ‬
‫ﺍﻟﺭﺋﻳﺳﻳﺔ‪.‬‬

‫‪In figure 1-8, the system asks to enter the student ID‬‬ ‫ﻋﻧﺩ ﺇﺩﺧﺎﻝ )‪ (2‬ﺍﻟﺧﻳﺎﺭ ﺍﻟﺛﺎﻧﻲ ﻓﻲ ﺍﻟﻘﺎﺋﻣﺔ ﻭﻫﻭ ﺍﻋﺎﺩﺓ‬
‫‪number and Book number (in the red color). Then the‬‬ ‫ﺍﻟﻛﺗﺎﺏ ﻳﻧﻘﻠﻧﺎ ﺍﻟﻧﻅﺎﻡ ﺍﻟﻰ ﺍﻟﺷﻛﻝ ‪.9-1‬‬
‫‪system searches for student name and the book title and‬‬
‫‪displays them below (in green color) and asks the user to‬‬ ‫ﻣﻥ ﻫﺫﺍ ﺍﻟﺷﻛﻝ ﻧﻼﺣﻅ ﺃﻥ ﺍﻟﻧﻅﺎﻡ ﻁﻠﺏ ﺇﺩﺧﺎﻝ ﺭﻗﻡ‬
‫‪confirm the information by entering (Y) for yes or (N) for no.‬‬ ‫ﺍﻟﻛﺗﺎﺏ ﻓﻘﻁ )ﺑﺎﻟﻠﻭﻥ ﺍﻷﺣﻣﺭ(‪ ،‬ﺣﻳﺙ ﻳﻌﺭﺽ ﺍﺳﻡ‬
‫‪Once the task ends, the system goes back to the main‬‬ ‫ﺍﻟﻁﺎﻟﺏ ﻭﻋﻧﻭﺍﻥ ﺍﻟﻛﺗﺎﺏ )ﺑﺎﻟﻠﻭﻥ ﺍﻷﺧﺿﺭ( ﻭﻳﻁﻠﺏ‬
‫‪menu.‬‬ ‫ﻣﻥ ﺍﻟﻣﺳﺗﺧﺩﻡ ﺍﻟﺗﺄﻛﺩ ﻣﻥ ﺍﻟﻣﻌﻠﻭﻣﺎﺕ ﻭﻓﻲ ﺣﺎﻝ ﺍﻟﺗﺄﻛﺩ‬
‫‪When the user enters the second choice, that is returning‬‬ ‫ﻳﻘﻭﻡ ﺍﻟﻣﺳﺗﺧﺩﻡ ﺑﺈﺩﺧﺎﻝ ﺍﻟﺣﺭﻑ )‪ (Y‬ﻟﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ‬
‫‪book; the system displays the Return Book screen, as‬‬ ‫ﺑﺗﺄﻛﻳﺩ ﺇﻋﺎﺩﺓ ﺍﻟﻛﺗﺎﺏ ﻭﺇﻟﻐﺎء ﺍﻹﻋﺎﺭﺓ‪ ،‬ﻛﺣﺫﻑ ﺭﻗﻡ‬
‫‪shown in figure 1-9. We should notice that the system‬‬ ‫ﺍﻟﻁﺎﻟﺏ ﻣﻥ ﺳﺟﻝ ﺍﻟﻛﺗﺎﺏ ﻣﺛﻼ‪ .‬ﻭﻣﻥ ﺛﻡ ﻳﻌﻭﺩ ﺇﻟﻰ‬
‫‪asks the user for book numbers only (in red). The system‬‬ ‫ﺷﺎﺷﺔ ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‪ .‬ﺃﻣﺎ ﻓﻲ ﺣﺎﻟﺔ ﺃﺩﺧﻝ ﺍﻟﻣﺳﺗﺧﺩﻡ‬
‫‪displays the student name and the book title and asks for‬‬ ‫ﺍﻟﺣﺭﻑ )‪ (N‬ﻳﻘﻭﻡ ﺍﻟﻧﻅﺎﻡ ﺑﺈﻟﻐﺎء ﺍﻟﻌﻣﻠﻳﺔ ﻭﺍﻟﻌﻭﺩﺓ ﺇﻟﻰ‬
‫‪confirmation. Once the user enters (Y), the system‬‬ ‫ﺍﻟﻘﺎﺋﻣﺔ ﺍﻟﺭﺋﻳﺳﻳﺔ‪.‬‬
‫‪operates and then return to the main menu as before.‬‬

‫‪1.7‬‬ ‫‪CONCLUSION‬‬

‫‪As we mentioned previously, the main objective of‬‬ ‫ﻛﻣﺎ ﺫﻛﺭﻧﺎ ﺳﺎﺑﻘﺎ ﺇﻥ ﺍﻟﻬﺩﻑ ﺍﻟﺭﺋﻳﺳﻲ ﻣﻥ ﺩﺭﺍﺳﺔ ﻫﻳﺎﻛﻝ‬
‫‪studying Data Structures is to use it in the‬‬ ‫ﺍﻟﺑﻳﺎﻧﺎﺕ ﻫﻭ ﺍﺳﺗﺧﺩﺍﻣﻬﺎ ﻓﻲ ﺗﻁﻭﻳﺭ ﺍﻟﺑﺭﻣﺟﻳﺎﺕ ﺃﻱ ﺑﺭﻣﺟﺔ‬
‫‪development of computer applications. We have‬‬ ‫ﺍﻟﺗﻁﺑﻳﻘﺎﺕ ﻭﺍﻷﻧﻅﻣﺔ ﺍﻟﺣﺎﺳﻭﺑﻳﺔ‪ .‬ﻭﻟﺻﻧﻊ ﻫﺫﻩ ﺍﻟﺗﻁﺑﻳﻘﺎﺕ‬
‫‪presented the steps to make applications free of errors‬‬ ‫ﻫﻧﺎﻟﻙ ﻋﺩﺩ ﻣﻥ ﺍﻟﺧﻁﻭﺍﺕ ﺍﻟﺗﻲ ﻳﺟﺏ ﺍﺗﺑﺎﻋﻬﺎ ﻟﻠﻭﺻﻭﻝ ﺇﻟﻰ‬
‫‪in simple way. In the following chapter, we will present‬‬ ‫ﺗﻁﺑﻳﻘﺎﺕ ﻧﺎﺟﺣﺔ ﻭﺧﺎﻟﻳﺔ ﻣﻥ ﺍﻷﺧﻁﺎء‪ ،‬ﻭﻗﻣﻧﺎ ﺑﺷﺭﺡ ﻫﺫﻩ‬
‫‪how to write programs using C++, C#, and java‬‬ ‫ﺍﻟﺧﻁﻭﺍﺕ ﺑﺷﻛﻝ ﺑﺳﻳﻁ ﻓﻲ ﺍﻷﺟﺯﺍء ﺍﻟﺳﺎﺑﻘﺔ ﻭﺳﻧﻘﻭﻡ‬
‫‪programming languages.‬‬ ‫ﺑﻌﺭﺽ ﻛﻳﻔﻳﺔ ﺻﻧﻊ ﻫﺫﻩ ﺍﻟﺑﺭﺍﻣﺞ ﺑﺎﺳﺗﺧﺩﺍﻡ ﻟﻐﺎﺕ ﺍﻟﺑﺭﻣﺟﺔ‬
‫ﺳﻲ‪ ++‬ﻭﺳﻲ‪ #‬ﻭﺟﺎﻓﺎ ﻓﻲ ﺍﻟﻭﺣﺩﺓ ﺍﻟﺛﺎﻧﻳﺔ‪.‬‬

‫‪13‬‬
Practical Data Structures with C++, C#, and Java

1.8. EXERCISES

1. Data Structures is about


a. Organizing data
b. Managing data
c. Storing data
d. All of the above

2. Programs reserve space for data in the


a. Hard Disk
b. Magnetic Tape
c. Main Memory
d. Read-Only Memory

3. Data may take the form of


a. Numbers
b. Strings
c. Characters
d. All of the above

4. When we run a program, the operating system loads it into


a. ROM
b. RAM
c. CPU
d. OS

5. Boot Loaders are small programs that live in


a. ROM
b. RAM
c. CPU
d. Hard Disk

6. The smallest unit of data is the


a. Byte
b. Bit
c. Number
d. Word

7. Coding Systems are developed to standardize the


a. CPU
b. data
c. computer instructions
d. operating systems

8. We declare variables in our programs to hold


a. codes
b. data
c. operating systems
d. instructions

9. The aim of studying data structures is to


a. develop computer hardware
b. develop computer software
c. write machine instructions

14
M.A. Eljinini

d. analyze programs

10. The first step for problem-solving is


a. analyze the problem
b. understand the problem
c. design the solution
d. write computer code

11. Drawing Data Flow Diagrams (DFD) is part of


a. system design
b. system analysis
c. system implementation
d. system testing

12. The development of data structures is part of


a. system design
b. system analysis
c. system implementation
d. system testing

13. Writing computer programs is part of


a. system design
b. system analysis
c. system implementation
d. system testing

14. Writing Algorithms is part of


a. system design
b. system analysis
c. system implementation
d. system testing

15. To ensure that our software is “free of errors” is part of


a. system design
b. system analysis
c. system implementation
d. system testing

16. Add a fourth option to the books Application. This option is used to print a list of all the books.

17. Add a new option to the books Application, to print the borrowed books only.

18. Add a date attribute to the (Books) class, then add a new option to the menu to print all books
that are two weeks late.

19. Perform the steps, as described in this chapter, to design an application for reserving rooms in
a hotel. The new application allows for reserving rooms, returning rooms, searching for a room,
and printing all occupied rooms.

20. Design an application for renting cars. The new application allows users to rent a car, return a
car, search for a car, and print a list of rented cars.

15
Practical Data Structures with C++, C#, and Java

Dear Reader,

Thank you for your interest in my book. Please accept my sincere apologies for not
sharing the full text due to author/publisher agreements with some distributers.

I hope the above contents, which consist of table of contents, preface, and chapter
one, give you a good idea of what it is all about.

If you are still interested in my book, you may get the full copy from one of the
following sources:

Amazon (in Color)

Paperback: https://www.amazon.co.uk/dp/9957674005

E-Book: https://www.amazon.co.uk/dp/B082FLVH7V

LuLu (in Black & White)

Paperback: http://www.lulu.com/shop/ma-eljinini/practical-data-structures-with-c-c-
and-java/paperback/product-24446111.html

Jamalon (in Black & White – also offers home delivery service, and cash on
delivery for some regions)

Paperback: https://jamalon.com/en/catalog/product/view/id/37484836

I hope this information is helpful.

Best Wishes,
Mohammad Ali H. Eljinini, Ph.D.

16

View publication stats

You might also like