consolidate all repos to one for archive
This commit is contained in:
64
semester_2/programiranje_2/primeri/Example13/main.cpp
Normal file
64
semester_2/programiranje_2/primeri/Example13/main.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <iostream>
|
||||
/*
|
||||
struct Node {
|
||||
int el;
|
||||
Node* ptrNext;
|
||||
};
|
||||
|
||||
//void insertAtBeginning(Node* start, int n) {
|
||||
void insertAtBeginning(Node*& start, int n) {
|
||||
Node* ptrTemp = new Node;
|
||||
ptrTemp->el = n;
|
||||
ptrTemp->ptrNext = start;
|
||||
start=ptrTemp;
|
||||
}
|
||||
|
||||
//void print(Node*& start) {
|
||||
void print(Node* start) {
|
||||
while (start) {
|
||||
std::cout << start-> el << " ";
|
||||
start=start->ptrNext;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
void print(Node*& start) {
|
||||
//void print(Node* start) {
|
||||
Node* temp = start;
|
||||
while (temp) {
|
||||
std::cout << temp-> el << " ";
|
||||
temp=temp->ptrNext;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
*/
|
||||
|
||||
int main() {
|
||||
int a = 10;
|
||||
int b = 20;
|
||||
int* p_a = &a;
|
||||
int** p_p_a = &p_a;
|
||||
std::cout << "a " << &a << " " << a << std::endl;
|
||||
std::cout << "b " << &b << " " << b << std::endl;
|
||||
std::cout << "p_a " << &p_a << " " << p_a << " " << *p_a << std::endl;
|
||||
std::cout << "p_p_a " << &p_p_a << " " << p_p_a << " " << *p_p_a << " " << **p_p_a << std::endl;
|
||||
std::cout << "------------------------" << std::endl;
|
||||
/*
|
||||
//The nullptr keyword represents a null pointer value.
|
||||
Node* ptrStart = nullptr;
|
||||
insertAtBeginning(ptrStart, 3);
|
||||
insertAtBeginning(ptrStart, 2);
|
||||
insertAtBeginning(ptrStart, 1);
|
||||
print(ptrStart);
|
||||
print(ptrStart);
|
||||
|
||||
while (ptrStart) {
|
||||
Node* ptrTemp = ptrStart->ptrNext;
|
||||
delete ptrStart;
|
||||
ptrStart=ptrTemp;
|
||||
}
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user