This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def gen_primes(): | |
| D = {} | |
| q = 2 | |
| while True: | |
| if q not in D: | |
| yield q | |
| D[q * q] = [q] | |
| else: | |
| for p in D[q]: | |
| D.setdefault(p + q, []).append(p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C++ this pointer | |
| #include <iostream> | |
| using namespace std; | |
| class MyClass { | |
| int data; | |
| public: | |
| MyClass() { | |
| data = 100; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Linkedlist implementation using Classes in C++ | |
| #include <iostream> | |
| using namespace std; | |
| class Node { | |
| public: | |
| int data; | |
| Node* next; | |
| }; | |
| class LinkedList{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Simple Linked List Implementation in C++ | |
| #include <iostream> | |
| using namespace std; | |
| void insert(); // function prototype | |
| void display(); // function prototype | |
| void reverseList(); // function prototype | |
| struct node { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Simple Linked List Implementation in C++ | |
| #include <iostream> | |
| using namespace std; | |
| void insert(); // function prototype | |
| void display(); // function prototype | |
| struct node { | |
| int data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // struct with pointers C++ | |
| #include <iostream> | |
| using namespace std; | |
| struct Person { | |
| string name; | |
| int age; | |
| string sex; | |
| }; | |
| int main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| struct Person { | |
| string name; // name, age and sex are all public by default compared to class where its private by default | |
| int age; | |
| string sex; | |
| void printDetails(); | |
| }; | |
| void Person::printDetails() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| double sum(double* a, int size) { | |
| double total = 0; | |
| double *p = a; | |
| for (int i = 0; i < size; i++) { | |
| total = total + *p; | |
| p++; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| using namespace std; | |
| int sum(int a[], int size){ | |
| int total = 0; | |
| for (int i = 0; i < size; i ++) { | |
| total = total + a[i]; | |
| } | |
| return total; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // pointer example 1 | |
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| double chase = 0; | |
| double discover = 50000; | |
| double* balance = &chase; // balance is a pointer to chase account | |
| *balance = 1000; // Initial deposit | |
| *balance = *balance - 100; // withdraw 100$ |