嵌入式筆試刷題(第29天)
1. 實(shí)現(xiàn)字符串類 String 的構(gòu)造、析構(gòu)與賦值函數(shù)
class String { public: String(const char* str = NULL) { if (str) { m_data = new char[strlen(str) + 1]; strcpy(m_data, str); } else { m_data = new char[1]; *m_data = '\0'; } } String(const String &other) { m_data = new char[strlen(other.m_data) + 1]; strcpy(m_data, other.m_data); } ~String() { delete[] m_data; } String& operator=(const String &other) { if (this == &other) return *this; delete[] m_data; m_data = new char[strlen(other.m_data) + 1]; strcpy(m_data, other.m_data); return *this; } private: char* m_data; };
2. 八皇后問題 C 語言實(shí)現(xiàn)
#include <stdio.h> #define N 8 int count = 0; int board[N]; int isSafe(int row, int
剩余60%內(nèi)容,訂閱專欄后可繼續(xù)查看/也可單篇購買
嵌入式筆試專欄 文章被收錄于專欄
本專欄系統(tǒng)整理了嵌入式方向筆試中常見的知識(shí)點(diǎn)和高頻考題,涵蓋基礎(chǔ)理論、常用算法、C語言陷阱、操作系統(tǒng)原理、驅(qū)動(dòng)開發(fā)、常見外設(shè)通信協(xié)議(如 I2C/SPI/UART)、RTOS、Linux 內(nèi)核、以及實(shí)用電路知識(shí)等內(nèi)容。