31251 Lecture Notes - Lecture 2: Include Directive, Priority Queue, The Queue

69 views2 pages
4 Jun 2018
School
Course
Professor
Week 2 Lecture
Simple I/O
There are a number of ways to handle basic input and output in C++.
i ad out are i the iostrea lirary ad are iterpreted as streas of
information.
The same abstractions are used for the input and output of files. For file I/O, the
lirary fstrea is used ith ofstrea used for ritig ad ifstrea for readig.
Classes and Destructors
~ is a destrutor ad is used to aage eory, he oied ith the delete
keyword. Without deleting the data, the heap memory is not deallocated and there
is a memory leak.
Exceptions
Ulike Jaa, C++ a ath or thro aythig…it is ot liited or restrited i
any way.
Queues
The Queue is the basic FIFO structure which keeps things in order.
In an ADT queue, the queue is built through restricting features.
Deque is a less restricted queue, however not quite as unrestricted as a list. It is
double-ended and allows you to remove data at both ends. It allows treatment as
queue or stack, and allows more flexibility which is more useful in practice.
A priority queue is a queue, but elements are inserted by priority, and come out in a
priority order. It may need searching or sorting to be done in the middle to make it
work.
Stacks
A stack is like a queue but it has a last in first out structure (like a stack of things).
You a add to the top ad oly reoe fro the top.
Week 3 Lecture
Vectors
Vectors are the middle ground, in between arrays and lists.
Vectors offer a resizable array, similar to an Arraylist in Java.
They are a teplated lass, hih has a ariety of ethods ithi the lass.
One particular feature of the vector class is operator overloading, which allows you
to change the way an operator works (reusing the same symbol). For example, in the
vector class, square brackets allow you to treat the vector as an array.
push_ak is a ethod that puts soethig o the ed.
In the vector class, capacity and size are different things. Capacity shows the
potential capability, and size shows what it currently holds. Capacity only grows
he ore eleets are added, ad does’t shrik he eleets are reoed.
There is a function which can shrink the capacity so not as much memory/space is
used.
When you run out of space within the vector, the capacity is doubled.
In C++ libraries, type definitions are used to shorten std::etc::pointer.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

For file i/o, the li(cid:271)rary (cid:862)fstrea(cid:373)(cid:863) is used (cid:449)ith (cid:862)ofstrea(cid:373)(cid:863) used for (cid:449)riti(cid:374)g a(cid:374)d (cid:862)ifstrea(cid:373)(cid:863) for readi(cid:374)g. Classes and destructors (cid:862)~(cid:863) is a destru(cid:272)tor a(cid:374)d is used to (cid:373)a(cid:374)age (cid:373)e(cid:373)ory, (cid:449)he(cid:374) (cid:272)o(cid:373)(cid:271)i(cid:374)ed (cid:449)ith the delete keyword. Without deleting the data, the heap memory is not deallocated and there is a memory leak. Exceptions: u(cid:374)like ja(cid:448)a, c++ (cid:272)a(cid:374) (cid:862)(cid:272)at(cid:272)h(cid:863) or (cid:862)thro(cid:449)(cid:863) a(cid:374)ythi(cid:374)g it is (cid:374)ot li(cid:373)ited or restri(cid:272)ted i(cid:374) any way. Queues: the queue is the basic fifo structure which keeps things in order, deque is a less restricted queue, however not quite as unrestricted as a list. In an adt queue, the queue is built through restricting features. double-ended and allows you to remove data at both ends. It allows treatment as queue or stack, and allows more flexibility which is more useful in practice: a priority queue is a queue, but elements are inserted by priority, and come out in a priority order.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents