Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Programming> Data Structures and Algorithms> C++ Data Structures and Algorithms
C++ Data Structures and Algorithms
C++ Data Structures and Algorithms

C++ Data Structures and Algorithms: Learn how to write efficient code to build scalable and robust applications in C++

Arrow left icon
Profile Icon Wisnu Anggoro
Arrow right icon
$9.99$39.99
Full star iconFull star iconHalf star iconEmpty star iconEmpty star icon2.5(4 Ratings)
eBookApr 2018322 pages1st Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Table of content iconView table of contentsPreview book icon Preview Book

C++ Data Structures and Algorithms

Getting closer to an array

Anarray is a series of elements with the same data type that is placed in contiguous memory locations. This means that the memory allocation is assigned in consecutive memory blocks. Since it implements contiguous memory locations, the elements of the array can be individually accessed by the index. Let's take a look at the following array illustration:

As we can see in the preceding illustration, we have an array containing five elements. Since the array uses zero-based indexing, the index starts from0. This index is used to access the element value and to also replace the element value. The memory address stated in the illustration is for example purposes only. In reality, the memory address might be different. However, it illustrates that the memory allocation is contiguous. 

Now, if we want to create the preceding array in C++,...

Introduction to node

Thenode is the basic building block of many data structures which we will discuss in this book. Node has two functions. Its first function is that it holds a piece of data, also known as theValue of node. The second function is its connectivity between another node and itself, using an object reference pointer, also known as theNext pointer. Based on this explanation, we can create aNode data type in C++, as follows:

class Node
{
public:
int Value;
Node * Next;
};

We will also use the following diagram to represent a single node:

Now, let's create three single nodes using our newNode data type. The nodes will contain the values 7,14, and21 for each node. The code should be as follows:

Node * node1 = new Node;
node1->Value = 7;

Node * node2 = new Node;
node2->Value = 14;

Node * node3 = new Node;
node3->Value = 21;

Note...

Building a Singly Linked List ADT

TheSingly Linked List (also known as the linked list) is a sequence of items linked with each other. It's actually a chaining of nodes, where each node contains the item's value and the next pointer. In other words, each item in the linked list has a link to its next item in the sequence. The thing that differs between the linked list and the node chain is that the linked list has aHead and aTail pointer. TheHead informs the first item and theTail informs the last item in the linked list. Similar to the List ADT, we discussed earlier, the linked list hasGet(),Insert(),Search(), andRemove() operations, where all of the operations have the same functionality compared to List. However, since we now haveHead andTail pointers, we will also create others operations, and these areInsertHead(),InsertTail...

Technical requirements


To follow along with this chapter including the source code, we require the following:

Getting closer to an array


Anarray is a series ofelements with the same data type that is placed in contiguous memory locations. This means that the memory allocation is assigned in consecutive memory blocks. Since it implements contiguous memory locations, the elements of the array can be individually accessed by the index. Let's take a look at the following array illustration:

As we can see in the preceding illustration, we have an array containing five elements. Since the array uses zero-based indexing, the index starts from0. This index is used to access the element value and to also replace the element value. The memory address stated in the illustration is for example purposes only. In reality, the memory address might be different. However, it illustrates that the memory allocation is contiguous. 

Now, if we want to create the preceding array in C++, here is the code:

// Project: Array.cbp// File   : Array.cpp#include <iostream>using namespace std;int main(){    //...

Building a List ADT


list is a sequence of items with similar data types, where the order of the item's position matters.There are several common operations that areavailable in a List ADT, and they are:

  • Get(i), which will return the value of selected index, i. If the i index is out of bounds, it will simply return -1.
  • Insert(i, v), which will insert thev value at the position of index i.
  • Search(v), which will return the index of the first occurrence of v (if the v value doesn't exist, the return value is -1).
  • Remove(i), which will remove the item in thei index. 

Note

For simplicity, we are going to build a List ADT that acceptsint data only, from zero (0) and higher. 

Now, by using the array data type we discussed earlier, let's build a new ADT namedList which contains the preceding operations. We need two variables to hold the list of items (m_items) and the number of items in the list (m_count). We will make themprivate so that it cannot be accessed from the outside class. All four operations...

Left arrow icon

Page1 of 11

Right arrow icon
Download code iconDownload Code

Key benefits

  • •Use data structures such as arrays, stacks, trees, lists, and graphs with real-world examples
  • •Learn the functional and reactive implementations of the traditional data structures
  • •Explore illustrations to present data structures and algorithms, as well as their analysis, in a clear, visual manner

Description

C++ is a general-purpose programming language which has evolved over the years and is used to develop software for many different sectors. This book will be your companion as it takes you through implementing classic data structures and algorithms to help you get up and running as a confident C++ programmer.We begin with an introduction to C++ data structures and algorithms while also covering essential language constructs. Next, we will see how to store data using linked lists, arrays, stacks, and queues. Then, we will learn how to implement different sorting algorithms, such as quick sort and heap sort. Along with these, we will dive into searching algorithms such as linear search, binary search and more. Our next mission will be to attain high performance by implementing algorithms to string datatypes and implementing hash structures in algorithm design. We'll also analyze Brute Force algorithms, Greedy algorithms, and more.By the end of the book, you'll know how to build components that are easy to understand, debug, and use in different applications.

Who is this book for?

This book is for developers who would like to learn the Data Structures and Algorithms in C++. Basic C++ programming knowledge is expected.

What you will learn

  • •Know how to use arrays and lists to get better results in complex scenarios
  • •Build enhanced applications by using hashtables, dictionaries, and sets
  • •Implement searching algorithms such as linear search, binary search, jump search, exponential search, and more
  • •Have a positive impact on the efficiency of applications with tree traversal
  • •Explore the design used in sorting algorithms like Heap sort, Quick sort, Merge sort and Radix sort
  • •Implement various common algorithms in string data types
  • •Find out how to design an algorithm for a specific task using the common algorithm paradigms

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Apr 26, 2018
Length:322 pages
Edition :1st
Language :English
ISBN-13 :9781788831970
Category :
Languages :

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Product Details

Publication date :Apr 26, 2018
Length:322 pages
Edition :1st
Language :English
ISBN-13 :9781788831970
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
$199.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts
$279.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick iconExclusive print discounts

Frequently bought together


C++ High Performance
C++ High Performance
Read more
Jan 2018374 pages
Full star icon4.1 (21)
eBook
eBook
$9.99$39.99
$48.99
C++ Data Structures and Algorithms
C++ Data Structures and Algorithms
Read more
Apr 2018322 pages
Full star icon2.5 (4)
eBook
eBook
$9.99$39.99
$48.99
The Modern C++ Challenge
The Modern C++ Challenge
Read more
May 2018328 pages
Full star icon4 (7)
eBook
eBook
$9.99$29.99
$38.99
Stars icon
Total$136.97
C++ High Performance
$48.99
C++ Data Structures and Algorithms
$48.99
The Modern C++ Challenge
$38.99
Total$136.97Stars icon
Buy 2+ to unlock$7.99 prices - master what's next.
SHOP NOW

Table of Contents

10 Chapters
Learning Data Structures and Algorithms in C++Chevron down iconChevron up icon
Learning Data Structures and Algorithms in C++
Technical requirements
Introduction to basic C++
Developing abstract data types
Analyzing the algorithm
Summary
QA section
Further reading
Storing Data in Lists and Linked ListsChevron down iconChevron up icon
Storing Data in Lists and Linked Lists
Technical requirements
Getting closer to an array
Building a List ADT
Introduction to node
Building a Singly Linked List ADT
Building the Doubly Linked List ADT
Applying List and LinkedList using STL
Summary
QA section
Further reading
Constructing Stacks and QueuesChevron down iconChevron up icon
Constructing Stacks and Queues
Technical requirements
Building a Stack ADT
Building a Queue ADT
Building a Deque ADT
Summary
QA section
Further reading
Arranging Data Elements Using a Sorting AlgorithmChevron down iconChevron up icon
Arranging Data Elements Using a Sorting Algorithm
Technical requirements
Bubble sort
Selection sort
Insertion sort
Merge sort
Quick sort
Counting sort
Radix sort
Summary
QA section
Further reading
Finding out an Element Using Searching AlgorithmsChevron down iconChevron up icon
Finding out an Element Using Searching Algorithms
Technical requirements
Linear search
Binary search
Ternary search
Interpolation search
Jump search
Exponential search
Sublist search
Summary
QA section
Further reading
Dealing with the String Data TypeChevron down iconChevron up icon
Dealing with the String Data Type
Technical requirement
String in C++
Playing with words
Constructing a string from binary digits
Subsequence string
Pattern searching
Summary
QA section
Further reading
Building a Hierarchical Tree StructureChevron down iconChevron up icon
Building a Hierarchical Tree Structure
Technical requirements
Building a binary tree ADT
Building a binary search tree ADT
Building a balanced BST (AVL) ADT
Building a binary heap ADT
Summary
QA section
Further reading
Associating a Value to a Key in a Hash TableChevron down iconChevron up icon
Associating a Value to a Key in a Hash Table
Technical requirement
Getting acquainted with hash tables
Implementing a separate chaining technique
Implementing the open addressing technique
Summary
QA section
Further reading
Implementation of Algorithms in Real LifeChevron down iconChevron up icon
Implementation of Algorithms in Real Life
Technical requirements
Greedy algorithms
Divide and conquer algorithms
Dynamic programming
Brute-force algorithms
Randomized algorithms
Backtracking algorithms
Summary
QA section
Further reading
Other Books You May EnjoyChevron down iconChevron up icon
Other Books You May Enjoy
Leave a review - let other readers know what you think

Recommendations for you

Left arrow icon
Debunking C++ Myths
Debunking C++ Myths
Read more
Dec 2024226 pages
Full star icon5 (1)
eBook
eBook
$9.99$31.99
$39.99
Go Recipes for Developers
Go Recipes for Developers
Read more
Dec 2024350 pages
eBook
eBook
$9.99$31.99
$39.99
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (64)
eBook
eBook
$9.99$39.99
$49.99
$49.99
Asynchronous Programming with C++
Asynchronous Programming with C++
Read more
Nov 2024424 pages
Full star icon5 (1)
eBook
eBook
$9.99$33.99
$41.99
Modern CMake for C++
Modern CMake for C++
Read more
May 2024504 pages
Full star icon4.7 (13)
eBook
eBook
$9.99$39.99
$49.99
Learn Python Programming
Learn Python Programming
Read more
Nov 2024616 pages
Full star icon3.5 (2)
eBook
eBook
$9.99$35.99
$39.99
Learn to Code with Rust
Learn to Code with Rust
Read more
Sep 202557hrs 40mins
Full star icon5 (1)
Video
Video
$9.99$74.99
Modern Python Cookbook
Modern Python Cookbook
Read more
Jul 2024818 pages
Full star icon4.9 (17)
eBook
eBook
$9.99$43.99
$54.99
Right arrow icon

Customer reviews

Rating distribution
Full star iconFull star iconHalf star iconEmpty star iconEmpty star icon2.5
(4 Ratings)
5 star0%
4 star25%
3 star25%
2 star25%
1 star25%
Bill PDec 10, 2018
Full star iconFull star iconFull star iconFull star iconEmpty star icon4
This book looks good. Not a very thick book, but the author provides some interesting material. Note, my review is based on my initial glance through the book. I have not tried any of the algorithms and cannot vouch just yet for their correctness. Things look about right.
Amazon Verified reviewAmazon
Mutombo Matanda HervéFeb 16, 2020
Full star iconFull star iconFull star iconEmpty star iconEmpty star icon3
I would have liked more explanations and perhaps narrations than there currently are in the book. It was more of a : A constant is something that stays the same, here's example one... Now let's move on to the next chapter.
Amazon Verified reviewAmazon
Anthony DasNov 12, 2018
Full star iconFull star iconEmpty star iconEmpty star iconEmpty star icon2
Although I’ve learnt about various data structures over the years as a professional programmer, I’ve never had a formal education into them and wanted a text to solidify and expand my knowledge. Early on, however, you pick up that the author’s first language isn’t English. His sentences can be ambiguous and some only made sense because I already had some area knowledge with which I could piece together what was meant. This is very different to other programming texts I’ve read that have quite a precise way with words.The same lack of quality also pervaded the code. Although the code does adequately demonstrate the underlying mechanics fairly well, it’s very rough and “non-production”. Eg.:- C++98 use of naked pointers via new. Ok, so we don’t want to use smart pointers, but there’s not a single use of delete. Hence, there are memory leaks throughout.- “Animal dog = Animal();” Strange style.- void LinkedList<T>::RemoveHead(){…} forgets to update the Tail pointer if there was only one element (i.e. Head and Tail are the same element). Same thing in void DoublyLinkedList<T>::RemoveHead(){…}.- Builds an AVL tree class inheriting from base BST but doesn’t make overridden functions virtual within base.There are also times when the author doesn’t quite seem to understand what’s going on:- “To search for the desired element, we can use find() method provided by the vector.” But code then uses <algorithm> find(), there is no vector::find().- Conversely, “We can use the erase() method provided by the vector. To use this method, we also need to include the algorithm header.” He then correctly employs vector::erase() without needing <algorithm>.Chapter 9 is incomplete both in terms of content (“We will now show”… but then the section abruptly ends) and in terms of presentation (e.g. the font will randomly change in places). There’s a brief introduction for a linear congruential generator but with a = 1 and m = 10. Why couldn’t some proper values be used instead?I could go on but I’ve made my point. I did learn how to balance a binary search tree and a new sorting algorithm (radix), so the text did expand my knowledge. I also commend the author for at least trying to produce a text and help the community. But overall, I wouldn’t recommend as there are surely better texts out there. Even putting aside the monetary cost of the text, you will waste time trying to understand the author's use of English.
Amazon Verified reviewAmazon
Amazon CustomerOct 01, 2022
Full star iconEmpty star iconEmpty star iconEmpty star iconEmpty star icon1
This book unconventional syntax such as its for loops that get in the way of understanding concepts like linked lists. I did not find the material helpful for me to understand how to use linked lists.
Amazon Verified reviewAmazon

People who bought this also bought

Left arrow icon
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (64)
eBook
eBook
$9.99$39.99
$49.99
$49.99
Event-Driven Architecture in Golang
Event-Driven Architecture in Golang
Read more
Nov 2022384 pages
Full star icon4.9 (10)
eBook
eBook
$9.99$39.99
$49.99
$44.99
The Python Workshop Second Edition
The Python Workshop Second Edition
Read more
Nov 2022600 pages
Full star icon4.6 (19)
eBook
eBook
$9.99$41.99
$51.99
Template Metaprogramming with C++
Template Metaprogramming with C++
Read more
Aug 2022480 pages
Full star icon4.6 (13)
eBook
eBook
$9.99$37.99
$46.99
Domain-Driven Design with Golang
Domain-Driven Design with Golang
Read more
Dec 2022204 pages
Full star icon4.4 (18)
eBook
eBook
$9.99$35.99
$44.99
Right arrow icon

About the author

Profile icon Wisnu Anggoro
Wisnu Anggoro
Wisnu Anggoro is a Microsoft Certified Professional in C# programming and an experienced C/C++ developer. He has also authored the books Boost.Asio C++ Network Programming - Second Edition and Functional C# by Packt. He has been programming since he was in junior high school, which was about 20 years ago, and started developing computer applications using the BASIC programming language in the MS-DOS environment. He has solid experience in smart card programming, as well as desktop and web application programming, including designing, developing, and supporting the use of applications for SIM Card Operating System Porting, personalization, PC/SC communication, and other smart card applications that require the use of C# and C/C++. He is currently a senior smart card software engineer at CIPTA, an Indonesian company that specializes in innovation and technology for smart cards. He can be reached through his email at&nbsp;wisnu@anggoro.net
Read more
See other products by Wisnu Anggoro
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook?Chevron down iconChevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website?Chevron down iconChevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook?Chevron down iconChevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support?Chevron down iconChevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks?Chevron down iconChevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook?Chevron down iconChevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Create a Free Account To Continue Reading

Modal Close icon
OR
    First name is required.
    Last name is required.

The Password should contain at least :

  • 8 characters
  • 1 uppercase
  • 1 number
Notify me about special offers, personalized product recommendations, and learning tips By signing up for the free trial you will receive emails related to this service, you can unsubscribe at any time
By clicking ‘Create Account’, you are agreeing to ourPrivacy Policy andTerms & Conditions
Already have an account? SIGN IN

Sign in to activate your 7-day free access

Modal Close icon
OR
By redeeming the free trial you will receive emails related to this service, you can unsubscribe at any time.

[8]ページ先頭

©2009-2025 Movatter.jp