for Robot Artificial Inteligence

SSH 파일 GUI로 쉽게 옮기(FileZilla) 및 손쉽게 Folder(window) path 찾기

|

Opensource FileZilla를 이용하여서 SSH GUI를 통하여 손쉽게 데이터를 옮길수 있다.

손쉽게 Folder(window) path 찾기

ctrl + L or command + L

Comment  Read more

Double Pointers Example

|

why use pointer

“Use ** when you want to preserve (OR retain change in) the Memory-Allocation or Assignment even outside of a function call”

알고리즘에서는 보통 class 및 struct안에 포인터가 자기 자신을 가르키고 있거다 할경우 사용이 된다[K-D 행렬 및 doublely linked list ]

Example

#include <iostream>
using namespace std;
//node declaration for doubly linked list
struct Node {
   int data;
   struct Node * prev, *next;
};

Node* newNode(int val)
{
   Node* temp = new Node;
   temp->data = val;
   temp->prev = temp->next = nullptr;
   return temp;
}
void displayList(Node* head)
{
   while (head->next != nullptr) {
      cout << head->data << " <==> ";
      head = head->next;
      }
   cout << head->data << endl;
}

// Insert a new node at the head of the list
void insert(Node** head, int node_data)
{
   Node* temp = newNode(node_data);
   temp->next = *head;
   (*head)->prev = temp;
   (*head) = temp;
}

// reverse the doubly linked list
void reverseList(Node** head)
{
   Node* left = *head, * right = *head;

   // traverse entire list and set right next to right
   while (right->next != nullptr)
   right = right->next;

   //swap left and right data by moving them towards each other till they meet or cross
   while (left != right && left->prev != right) {

      // Swap left and right pointer data
      swap(left->data, right->data);

      // Advance left pointer
      left = left->next;

      // Advance right pointer
      right = right->prev;
   }
}
int main()
{
   Node* headNode = newNode(5); // assigned pointer Node
   /*
   data = 5;
   struct Node * prev = null, *next = null;
   */
   insert(&headNode, 4); // of course when parsing pointer need to be in reference for another not initialized pointer pointing already existing variable of pointer.
   // A reference is an alias for an already existing variable.
   insert(&headNode, 3);
   insert(&headNode, 2);
   insert(&headNode, 1);
   cout << "Original doubly linked list: " << endl;
   displayList(headNode);
   cout << "Reverse doubly linked list: " << endl;
   reverseList(&headNode);
   displayList(headNode);

   return 0;
}

Note

A pointer in C++ is a variable that holds the memory address of another variable. Reference is C++ is an address(box of memory address and value)

A reference is an alias for an already existing variable. Once a reference is initialized to a variable, it cannot be changed to refer to another variable. Hence, a reference is similar to a const pointer.

reference is often used in LValue which is not copy variable. just alias it in directly in the allocating memory of it and change value directly already in

on Rvalue of reference is address(box) of value or some value.

and pointer need to have create allocate memory or pointing to already existent memory in heap or stack somewhere.

thats why it need to pointing reference(Rvalue way, address) memory of variable and initialise pointer.

easy understand address is box and value is inside box

간단

point가 Lvalue일때는 어드레스를 가르키고, RVALUE일때는 Value를 가르켜야하기 때문에 “*“를 쓴다.

Reference가 LValue일때는 Rvalue(variable)에 대한 Alias, RValue일때는 variable에 대한 Address

Comment  Read more

colorized std::cout and definition of inline function and typename and using and typedef and header

|

colored-output-in-c

#ifndef UTILS_COLOR_HPP_
#define UTILS_COLOR_HPP_

#define CLI_NORMAL      "\033[1m\033[0m"
#define CLI_RED         "\033[1m\033[31m"
#define CLI_GREEN       "\033[1m\033[32m"
#define CLI_YELLOW      "\033[1m\033[33m"
#define CLI_BLUE        "\033[1m\033[34m"
#define CLI_MAGENTA     "\033[1m\033[35m"
#define CLI_CYAN        "\033[1m\033[36m"
#define CLI_WHITE       "\033[1m\033[37m"
#define CLI_LIGHT_RED         "\033[1m\033[91m"
#define CLI_LIGHT_GREEN       "\033[1m\033[92m"
#define CLI_LIGHT_YELLOW      "\033[1m\033[93m"
#define CLI_LIGHT_BLUE        "\033[1m\033[94m"
#define CLI_LIGHT_MAGENTA     "\033[1m\033[95m"
#define CLI_LIGHT_CYAN        "\033[1m\033[96m"
#define CLI_LIGHT_WHITE       "\033[1m\033[97m"
#endif  // UTILS_COLOR_HPP_

inline-function-in-cpp

typename

difference between class and typename

difference between typedef and using

Haeder print method


void PrintHeading1(const std::string& heading) {

std::cout << std::endl << std::string(78, '=') << std::endl;

std::cout << heading << std::endl;

std::cout << std::string(78, '=') << std::endl << std::endl;

}

void PrintHeading2(const std::string& heading) {

std::cout << std::endl << heading << std::endl;

std::cout << std::string(std::min<int>(heading.size(), 78), '-') << std::endl;

}

Comment  Read more

Rvalue Reference(double address &&)가 무엇이고 왜 쓰는지 and "return *this" mean and "return reference" mean

|

RValue Reference definition

Move Semantic(Copy and Deconstuction을 반복하지 않고 효율적으로 데이터 처리하는 법), 여러 struct 및 class가진 데이터 구조를 vector나 어떤 컨테이너를 넣을때 효율적으로 할 때 사용(Move Construction)

Forwarding Problem과 Perfect Forwarding 여러 매개변수의 함수를 General하게 다 사용할 수 있도록 하는 곳에 사용(데이터 타입 캐스팅 가능)

RValue Reference와 LValue Reference를 받는 함수를 오버로딩 및 캐시팅할때 사용

RValue Reference는 즉 temporally Hold Value and Move it, not copy.

“return reference” mean, copy가 아닌 LValue형식으로 global 변수가 있다고 가정을 할때 해당 메모리의 value를 바꿀때 사용

“return *this” mean, 바뀐 자기 자신의 class를 reference(LValue)타입 으로 자신 class메모리의 value를 변경

Comment  Read more

LAMDA C++

|

Comment  Read more