cpp-containers-iterators
containerAn object that allows us to collect other objects together and interact with them in some way. (vectors, stacks, queues!)why containers?
organization
standardization
abstractionwe have used the idea for structs:12345678910struct Student {string name; // these are called fieldsstring state; // separate these by semicolonsint age;};Student s;s.name = "Fabio";s.state = "FL";s.age = 21; // use . to access fields
what if there are a whole class of students?Typi ...
Cpp-types, structs, ini, ref, streams
very basic STL12345#include <iostream>int main() {std::cout << "Hello, world!" << std::endl;return 0;}
std:::The STL
Tons of general functionality
Built in classes like maps, sets, vectors
Accessed through the namespace std::
Extremely powerful and well-maintainedusing namespace std; is not a good style!
typesmore fundemental types: std::string str = "Haven";C++: a interpreted language (Types before program runs during compilation)C++ allows func ...
61C-P3-RISC-v
Assembly languagedefinition
Different CPUs implement different sets of instructions. The set of instructions a particular CPU implements is an Instruction Set Architecture (ISA), and the programming language defined by the ISA is commonly known as an assembly language.
Examples: ARM (cell phones), Intel x86 (i9, i7, i5, i3), IBM/Motorola PowerPC (old Macs), MIPS, RISC-V, …
risc-vCS 61C Reference Card
https://cs61c.org/sp24/pdfs/resources/reference-card.pdf
Lists out the entire base arc ...
61C-P2-number
binarybasics
A system of storing data using just two digits: 1 and 0.
Everything in a computer is ultimately stored in binary (high voltage wire = 1, low voltage wire = 0)
Generally rooted in the mathematical concept of binary (as a base 2 system of representing numbers)
Since computers tend to “think” in binary, it is ultimately useful to work with values in binary. By convention we prepend any binary value with “0b”
operations&, |, ~, ^: convert every<<, >>:
Left s ...
61C-P0-debug
gdbGDB commands:![[Pasted image 20240522101140.png]]![[Pasted image 20240522101153.png]]
valgrindbugs: bohrbug: can appear in certain conditionsheisenbugs: cannot appear in the debugging processWe can use a tool called Valgrind to help catch to help catch “heisenbugs” and “bohrbugs”.emulates your CPU and tracks your memory accesses!
1valgrind ./bork hello
61C-P1-C
Compilegcc hello.ccreates machine language codea.out loads andexecutes programgreat idea in C:![[Pasted image 20240519124500.png]]
basic grammarsinput12345#include <stdio.h>int main(int argc, char *argv[]) { // printf("Hello World!\n");return 0;}
Combined, argc and argv get the main function to accept arguments.
argc will contain the number of strings on the command line (the executable counts as one, plus one for each argument). Here argc is 2:
./a.out myFile
argv is ...
61B-P5-6-sort
definitionsAn ordering relation << for keys a, b, and c has the following properties:
Law of Trichotomy: Exactly one of a << b, a = b, b << a is true.
Law of Transitivity: If a << b, and b << c, then a << c.
Java: ComparableIn java, compare or compareTo methods are used.
1234567import java.util.Comparator; public class LengthComparator implements Comparator<String> { public int compare(String x, String b) { return x.length() - ...
61B-P5-5-QuadTree
questionSuppose we want to perform operations on a set of Body objects in space. For example, perhaps we wanted to ask questions about the Sun bodies (shown as yellow dots below) in our two-dimension image space.How many objects are in a region?
HashTableiterate over all items to checkproblem: totally random!
uniform partitioningOur attempt is to ensure that the bucket numbers depend only on position! uniformly partition our image space by throwing a 4x4 grid over it (“spatial hashing”) implemen ...
C++-intro
C BasicsWhat C++ brings:
Almost all the aspects of C are preserved
New features are added, e.g., templates, references
Sophisticated programs are easier to code, thanks to OOP
C++ is almost a superset of Cnew data types: bool a = false, b = true;new headers: 12#include <iostream>using namespace std;
new I/O style:
input: cin >> x
output: cout << 'string'
formatting output:
setw(int width): set the width of the output
setfill(z): set up the prefix (前缀) of the outp ...
C-intro
Basic Linux tar usagetar -xvf xxx.tar unziptar -cf xxx.tar ... xxx.c zip
basic data typesInteger: intCharacter: charValueless type: voidFractional numbers: Singleprecision: floatDouble precision: doubleVarious types variations:char: signed char, unsigned charint: short int, signed short int, unsigned short int, signed int, unsigned int, long int, signed long int, unsigned long int, long long int, signed long long int, unsigned long long intdouble: long double
Basic number typesfloat: 7 digits of ...
