Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++
C++
  1. Tokenizing a string in C++ (การแบ่งสตริงเป็นโทเคน)

    ในส่วนนี้ เราจะดูวิธี tokenize strings ใน C++ ใน C เราสามารถใช้ฟังก์ชัน strtok() สำหรับ character array ได้ ที่นี่เรามี string class ตอนนี้เราจะดูวิธีตัด string โดยใช้ delimiter จาก string นั้น เพื่อใช้ C++ feature เราต้องแปลง string เป็น string stream แล้วใช้ getline() function ก็สามารถทำได้ ฟังก์

  2. วิธีง่ายที่สุดในการแปลง int เป็น string ใน C++

    ในส่วนนี้ เราจะดูวิธีแปลง integer เป็น string ตรรกะง่ายมาก ที่นี่เราจะใช้ฟังก์ชัน sprintf() ฟังก์ชันนี้ใช้พิมพ์ค่าหรือบรรทัดเข้าไปใน string แต่ไม่ใช่ในคอนโซล นี่คือความแตกต่างเดียวระหว่าง printf() และ sprintf() ที่นี่ argument แรกคือ string buffer ที่เราต้องการเก็บข้อมูล Input: User will put some n

  3. C++ Program to Implement Ternary Tree

    Ternary tree เป็นโครงสร้างข้อมูลต้นไม้ที่แต่ละโหนดมี child nodes สูงสุดสามตัว มักแสดงเป็น left, mid และ right ในต้นไม้นี้ โหนดที่มีลูกเป็น parent nodes และ child nodes อาจมี reference ไปยัง parent ของพวกเขา นี่คือ C++ Program เพื่อ Implement Ternary Tree และการ traverse ต้นไม้ Algorithm Begin D

  4. C++ Program to Perform Dictionary Operations in a Binary Search Tree

    Binary Search Tree เป็น binary tree ที่จัดเรียงแล้ว ซึ่งทุกโหนดมีคุณสมบัติสองอย่าง - Right sub-tree ของโหนดมี key มากกว่า key ของ parent node Left sub-tree ของโหนดมี key น้อยกว่าหรือเท่ากับ key ของ parent node แต่ละโหนดไม่ควรมีลูกมากกว่าสอง นี่คือ C++ Program เพื่อ Perform Dictionary Operations ใน

  5. C++ Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree

    ถ้า binary tree ถูก traverse แบบ in-order จะเยี่ยม left subtree ก่อน แล้ว root และภายหลัง right sub-tree Output จะได้ key เรียงจากน้อยไปมากใน in-order traversal นี่คือ C++ Program สำหรับ Inorder Tree Traversal โดยไม่ใช้ Recursion Algorithm Begin Declare a structure n. Declare d of the i

  6. C++ Program to Perform Left Rotation on a Binary Search Tree

    Binary Search Tree เป็น binary tree ที่จัดเรียงแล้ว ซึ่งทุกโหนดมีคุณสมบัติสองอย่าง - Right sub-tree ของโหนดมี keys ทั้งหมดมากกว่า key ของ parent node Left sub-tree ของโหนดมี keys ทั้งหมดน้อยกว่า key ของ parent node แต่ละโหนดไม่ควรมีลูกมากกว่าสอง Tree rotation เป็นการดำเนินการที่เปลี่ยนโครงสร้างโดยไ

  7. C++ Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree

    ถ้า binary tree ถูก traverse แบบ post-order จะเยี่ยม left subtree ก่อน แล้ว right sub-tree และภายหลังถึง root นี่คือ C++ Program สำหรับ Post Order Tree traversal โดยไม่ใช้ recursion เราทำโปรแกรมนี้โดยใช้ stack Algorithm For postorder traversal: Begin Declare postorder_traversal(struct node*t,st

  8. C++ Program to Perform Right Rotation on a Binary Search Tree

    Binary Search Tree เป็น binary tree ที่จัดเรียงแล้ว ซึ่งทุกโหนดมีคุณสมบัติสองอย่าง - Right sub-tree ของโหนดมี key มากกว่า key ของ parent node Left sub-tree ของโหนดมี key น้อยกว่าหรือเท่ากับ key ของ parent node แต่ละโหนดไม่ควรมีลูกมากกว่าสอง Tree rotation เป็นการดำเนินการที่เปลี่ยนโครงสร้างโดยไม่รบก

  9. ทำไม std::getline() ถึงข้าม input หลัง formatted extraction?

    std::getline() ข้าม input หลัง formatted extraction บางอย่าง เราสามารถตรวจสอบ error นี้จากโค้ดต่อไปนี้ - ตัวอย่างโค้ด #include <iostream> #include <string> using namespace std; int main(){ string name; string city; if (cin >> name && getline(cin, city)){

  10. Single quotes ใน C++ ทำอะไรเมื่อใช้กับหลายตัวอักษร?

    ใน C++ ใน C++ double quotes ใช้เป็น string literals และ single quote กับตัวอักษรเดียวใช้เป็น character literals ตอนนี้เราจะดูว่าถ้าเราพยายามพิมพ์ multi-character string ด้วย single quote จะได้ผลลัพธ์อะไร ตัวอย่างโค้ด #include<iostream> using namespace std; main() { cout << ABCD; } ผ

  11. ความแตกต่างระหว่าง Pass by Value และ Pass by Reference ใน C++

    ใน C++ เราสามารถส่ง arguments ให้ฟังก์ชันได้หลายวิธี วิธีเหล่านี้คือ - Call by Value Call by Reference Call by Address บางครั้ง Call by Address ถูกอ้างว่าเป็น Call by Reference แต่ใน C++ พวกมันต่างกัน ใน Call by Address เราใช้ตัวแปร pointer เพื่อส่งที่อยู่หน่วยความจำที่แน่นอน แต่ใน Call by Refere

  12. C++ Program to Print only Odd Numbered Levels of a Tree

    นี่คือโปรแกรม C++ เพื่อพิมพ์เฉพาะ Odd Numbered Levels (ระดับคี่) ของ Tree Algorithm (อัลกอริทึม) โครงสร้างและฟังก์ชันพร้อม pseudocode: Begin Declare nod as a structure. Declare d of integer datatype. Declare a pointer l against struct nod. Declare a pointer r against str

  13. ทำไมต้องเรียก cin.clear() และ cin.ignore() หลังอ่าน input ใน C++?

    ใน C++ cin ใช้รับ input จากผู้ใช้ บางครั้งด้วยเหตุผลบางอย่าง error flags บางอย่างถูกตั้งค่า ในขณะนั้น cin ไม่รับ input ใดๆ บางครั้งมันรับตัวอักษรอื่นๆ เข้าไป ดังนั้นถ้าเรา clear cin แล้ว error flags จะถูก reset แล้วเราสามารถใช้ getline(), get() เป็นต้นได้ ฟังก์ชัน ignore() เป็นฟังก์ชัน stream input

  14. ทำไมการละเลย curly braces ใน C/C++ ถึงถือเป็น bad practice?

    ใน C++ เราสามารถละเลย curly braces หลัง if-else statements หรือหลัง loop ใดๆ ได้ หากเราไม่ใช้ curly braces จะมีเพียงคำสั่งเดียวหลัง if-else หรือ loop ที่ถูกนับว่าอยู่ในบล็อกนั้น ตัวอย่าง - if(condition) { Line 1 Line 2 } if(condition) Line 1 Line 2 ในกรณีแรก Line1 และ Line2 ทั้งคู่อ

  15. ทำไมต้องใช้ static_cast<int>(x) แทน (int)x ใน C++?

    (int)x เป็น C-style typecasting ในขณะที่ static_cast<int>(x) ใช้ใน C++ static_cast<>() ให้การตรวจสอบที่ compile-time (เวลาคอมไพล์) แต่ C-style casting ไม่รองรับการตรวจสอบนี้ static_cast<>() สามารถเห็นได้ชัดเจนที่ไหนก็ตามในโค้ด C++ และการใช้ C++ cast นี้สื่อความตั้งใจได้ชัดเจนกว่า

  16. C++ Program to Print the Kind of Rotation the AVL Tree is Undergoing When you Add an Element or Delete an Element

    AVL tree เป็น Binary Search Tree ที่ทำการปรับสมดุลด้วยตัวเอง โดยที่ความแตกต่างของความสูงระหว่าง subtree ซ้ายและขวาไม่เกินหนึ่งสำหรับทุกโหนด Tree rotation (การหมุนต้นไม้) เป็นการดำเนินการที่เปลี่ยนโครงสร้างโดยไม่รบกวนลำดับของ elements บน AVL tree มันย้ายโหนดหนึ่งขึ้นในต้นไม้และอีกโหนดหนึ่งลง ใช้เพื่

  17. Single quotes vs double quotes ใน C หรือ C++

    ใน C และ C++ เครื่องหมาย single quote ใช้ระบุ single character (ตัวอักษรเดี่ยว) และ double quotes ใช้สำหรับ string literals (ค่าคงที่สตริง) String literal x เป็นสตริง ประกอบด้วย character x และ null terminator \0 ดังนั้น x ในกรณีนี้เป็น array ของตัวอักษรสองตัว ใน C++ ขนาดของ character literal เป็น

  18. Dangling, Void, Null และ Wild Pointers ใน C/C++

    Dangling Pointer Dangling pointer คือ pointer ที่ชี้ไปยังตำแหน่งหน่วยความจำที่ถูกปล่อย (หรือลบ) แล้ว มีหลายวิธีที่ pointer กลายเป็น dangling pointer Function Call Pointer ที่ชี้ไปยังตัวแปร local จะกลายเป็น dangling เมื่อตัวแปร local ไม่ใช่ static int *show(void) { int n = 76; /* ... */ retu

  19. Pass by Value หรือ Pass by Reference ใน C++ อันไหนดีกว่า?

    ใน C++ เราสามารถส่ง argument ให้ฟังก์ชันได้หลายวิธี วิธีเหล่านี้คือ - Call by Value Call by Reference Call by Address บางครั้ง Call by Address ถูกอ้างว่าเป็น Call by Reference แต่ใน C++ พวกมันต่างกัน ใน Call by Address เราใช้ตัวแปร pointer เพื่อส่งที่อยู่หน่วยความจำที่แน่นอน แต่ใน Call by Referen

  20. การประกาศ Interface ใน C++

    Interface (อินเตอร์เฟซ) อธิบายพฤติกรรมหรือความสามารถของคลาส C++ โดยไม่ผูกมัดกับการใช้งานเฉพาะของคลาสนั้น Interface ใน C++ ถูกนำไปใช้โดยใช้ abstract classes (คลาสนามธรรม) และคลาสนามธรรมเหล่านี้ไม่ควรสับสนกับ data abstraction (การนามธรรมข้อมูล) ซึ่งเป็นแนวคิดในการแยกข้อมูลการใช้งานออกจากข้อมูลที่เกี่

Total 6007 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:37/301  20-คอมพิวเตอร์/Page Goto:1 31 32 33 34 35 36 37 38 39 40 41 42 43