31251 Lecture Notes - Lecture 1: Computational Problem

54 views2 pages
What’s an Algorithm?
A well-defined computational process that takes some input and produces an
output.
Really, it’s a tool for solving a well specified computational problem.
You don’t actually need a computer for them though.
What is a Data Structure?
A way to store and organise data.
Really just a special type of algorithm.
Arrays in C++
(they look a lot like in java)
int a[4] = {1,2,3,4};
int a[] = {1,2,3,4};
int a[4] = {}; • int a[4];
The program does its own memory management – you need to know the size!
What if we don’t know the size?
Arrays decay to pointers to the first element.
So an int[] can be treated as a int*
To create a pointer to type t
t * foo;
The spaces around the * don’t matter (i.e t* foo, t * foo and t *foo are all the same).
A pointer is really just number that is the address of whatever it’s pointing at.
To get what it’s pointing at we dereference it:
t bar = *foo;
If you’re derefencing to get a member (*foo).bar, you can write the alternative foo-
>bar. This can be nicer in many situations.
To get the address of something, use the address operator:
int foo = 5; int * bar = &foo;
Static and Dynamic Allocation
C++ has a more complex allocation system than Java (at least from the programmer’s
perspective).
1 | P a g e
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

A well-defined computational process that takes some input and produces an output. Really, it"s a tool for solving a well specified computational problem. You don"t actually need a computer for them though. A way to store and organise data. Really just a special type of algorithm. Arrays in c++ (they look a lot like in java) int a[4] = {1,2,3,4}; int a[] = {1,2,3,4}; int a[4] = {}; int a[4]; The program does its own memory management you need to know the size! Arrays decay to pointers to the first element. So an int[] can be treated as a int* To create a pointer to type t t * foo; The spaces around the * don"t matter (i. e t* foo, t * foo and t *foo are all the same). A pointer is really just number that is the address of whatever it"s pointing at. To get what it"s pointing at we dereference it: t bar = *foo;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents