0% found this document useful (0 votes)
42 views4 pages

Array Dynamic Memory Allocation Why Use A Multidimensional Array? Example

1. A multidimensional array allows data to be organized into subgroups by using more than one series of elements. This can be useful for storing related data values. 2. A two-dimensional array consists of two arrays, with the first set of array elements containing the primary array and subsequent sets containing subarrays. Each set of array elements is itself an array. 3. A queue is a data structure that organizes items in a first-in, first-out order, with new items added to the rear of the queue and items removed from the front. Operations for adding (enqueue) and removing (dequeue) items are supported. Priority queues allow higher priority items to jump ahead in the queue.

Uploaded by

rheena espiritu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views4 pages

Array Dynamic Memory Allocation Why Use A Multidimensional Array? Example

1. A multidimensional array allows data to be organized into subgroups by using more than one series of elements. This can be useful for storing related data values. 2. A two-dimensional array consists of two arrays, with the first set of array elements containing the primary array and subsequent sets containing subarrays. Each set of array elements is itself an array. 3. A queue is a data structure that organizes items in a first-in, first-out order, with new items added to the rear of the queue and items removed from the front. Operations for adding (enqueue) and removing (dequeue) items are supported. Priority queues allow higher priority items to jump ahead in the queue.

Uploaded by

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

Array Example: int grades [10]; Why use a multidimensional array?

A way to reference a series of memory


locations using the same name. Each memory Dynamic Memory Allocation Example:
location is represented by an array element. Refers to managing system memory at Let’s say that a student has three grades, a
runtime. midterm grade, a final exam grade and a final
Array element this is similar to one variable grade.
except is it identified by an index value instead MULTIDIMENSIONAL Arrays You can store all three grades for an endless
of a name. number of students in a two-dimensional array,
ONE-DIMENSIONAL ARRAY - The array consist as shown:
Index value – a number to identify an array of one series of elements.
element. Figure 3-3
Why use a multidimensional array? All three grades can be stored in a
Array multidimensional array.
The array is called grades. The first • An array consists of more than one
element is called grades [0]. The zero is the series of elements.
index value. The square bracket tells the • This can be useful to organize
computer that the value inside the square subgroups of data within an array.
bracket is an index.
Char Letter [3][3]
Array's & DATA STRUCTURES
• A variable that contains a memory
address of another variable.
• Array Pointer - an indexed set
of variables in which the variables
are pointers (a reference to a location
in memory).
• Pointer to Pointer – a variable that  The first set of array elements contains
contains the address of another three array elements, one for each
pointer. student.
 The first of the four elements contains
Declaring an array Each set of array elements is an array. the Student ID and the other three
• Allocation – another way of saying The first set of array elements is considered the contain the three grades for that
reserving of memory. primary array, and the second and subsequent student ID.
Four components of a statement that declares sets of array elements are considered
an array: subarrays.
a. Data Type
b. Array Name Figure 3-2
c. Total numbers of array A two-dimensional array is a multidimensional
to create array consisting of two arrays.
d. Semicolon (;)
Declaring a multidimensional array Referencing – tells the computer to copy the LESSON 2. QUEUES USING AN ARRAY
memory address of the variable instead of
Five components of a statement that declares copying the value stored in the memory  QUEUE - A collection in which the
an array: address. entities in the collection are kept in
a. Data Type order and the principal (or only)
b. Array Name An array of pointers TO POINTERS operations on the collection are the
c. Total numbers of array addition of entities to the rear terminal
to create • Variable – a reference to a memory position, known as enqueue, and
d. Another total numbers location used to store data that is removal of entities from the front
of array to create described in a data type. terminal position, known as dequeue.
e. Semicolon (;) • Pointer variable – a memory address of
another pointer variable.  A sequential organization of data.
Example: int grades [3][4];
Declaring and using an array of pointers TO Simple QUEUE
Assigning values to a multidimensional array POINTERS  Organizes items in a line where the first
item is at the beginning of the line and
You assign a value to an element of a • An array of pointers to pointers is the last item is at the back of the line.
multidimensional array with an assignment declared nearly the same way as you  Each item is processed first, followed
statement similar to the assignment statement declare an array of pointers, except two by the second item and then the third
that assigns a value to a single-dimensional asterisks (**) are used before the name until the last item on the line is
array as shown below: of the array, as shown below: processed.
Example: grades [0] [0] = 1001; Example: String **ptStudents[3];
Priority QUEUE
You must specify the index of both String Data Type - A string is a data type used in  Similar to a simple queue in that items
dimensions. In this example, the integer 1001, programming, such as an integer and floating are organized in a line and processed
which is a student ID, is assigned to the first point unit, but is used to represent text rather sequentially. However, items on a
element of the first set of elements in the than numbers. It is comprised of a set priority can jump to the front of the line
grades array. of characters that can also contain spaces and if they have priority.
numbers.
An array of pointers Enqueue
For example, the word "hamburger" and the  The operation for adding an element
Symbols: phrase "I ate 3 hamburgers" are both strings. into a Queue.
 & - ampersand
 * - dereferences the pointer Dequeue
and tells the computer that you  The operation for removing an element
want the value pointed to by from Queue.
the pointer.
attempt is made to place a value on the LESSON 3. LINKED LIST
back of the queue.
LINKED LIST
isEmpty ( )  A data structure that makes it easy to
rearrange data without having to move
 A member function determines if the a data memory.
queue is empty by comparing the back
and front variables.
 A member function is called within the
dequeue ( ) member function before it
attempts to remove the front item from
the queue.
QUEUES Using an array in c++
enqueue ( )
queue.cpp
 File contains the implementation of the  A member function places an item at
member functions for the Queue class. the back of the queue, as described in
Five member functions defined in this file: the “Enqueue” section.
 ~Queue ( )  A member function is passed that value The structure of a linked list
 isFull ( ) that is to be placed in the queue.
 isEmpty ( ) node
 enqueue ( ) dequeue ( )
 dequeue ( )  An entry on a linked list.
Queue ( )  A member function removes an item Think of a node as an entry that has three
A member function is the destructor from the queue and returns that item subentries:
and uses the delete operator to remove the to the statement within the program a. One subentry contains data,
array from memory when the instance of the that calls the dequeue ( ) member which maybe one attribute or
Queue class goes out of scope. function. many attributes.
b. Second attribute is the Previous
isFull ( ) queueProgram.cpp node.
 Is where all the action takes place. It is c. Third attribute is the Next
 A member function determines if there here that an instance of the Queue class Node.
is a room available in a queue by is declared and manipulated.
comparing the calculated value of the
back of the queue with the value of the
front of the queue.

 a member function is called by


enqueue ( ) member function before an
SINGLE LINKED LIST
 References the next node and not the
previous node, although nothing stops
you from creating a backward reference
by using only the previous node
reference.

doubly LINKED LIST


 Also called as bidirectional.
 Each node contains to the previous and
next node on the linked list.

LINKED LIST class in C++


 Create and manage a linked list.
 Consist of two data members are
pointers to instances of the Node
structure.
First pointer: Front – references the first node
on the linked list.

Second pointer: Back – references the last node


on the linked list.

You might also like