ฟังก์ชันนี้ใช้เพื่อแทรกองค์ประกอบใหม่ที่ส่วนท้ายของ deque
ไวยากรณ์
dequename.emplace_back(value)
พารามิเตอร์
ค่า - กำหนดองค์ประกอบที่จะแทรกเมื่อสิ้นสุด deque
ตัวอย่าง
ป้อนข้อมูล เด็ค − 11 12 13 14 15
ผลผลิต ใหม่ Deque − 11 12 13 14 15 16
ป้อนข้อมูล Deque − M O M E N T
ผลผลิต ใหม่ Deque − M O M E N T S
แนวทางสามารถติดตามได้
-
ขั้นแรก เราประกาศเดค
-
จากนั้นเราก็พิมพ์ดีค
-
จากนั้นเราจะกำหนดฟังก์ชัน emplace_back( )
-
จากนั้นเราพิมพ์ deque ใหม่หลังจากใส่องค์ประกอบใหม่
โดยใช้วิธีการข้างต้น เราสามารถป้อนองค์ประกอบใหม่ในตอนท้าย ในขณะที่กำหนดฟังก์ชัน เรากำหนดองค์ประกอบใหม่เป็นพารามิเตอร์ องค์ประกอบใหม่ควรมีประเภทข้อมูลเหมือนกับ deque
ตัวอย่าง
// C++ code to demonstrate the working of deque emplace_back( ) function
#include<iostream.h>
#include<deque.h>
Using namespace std;
int main( ){
// initializing deque
deque<int> deque ={ 14, 15, 16, 17, 18 };
cout<< “ Deque: “;
for( auto x = deque.begin( ); x != deque.end( ); ++x)
cout<< *x << “ “;
// defining the emplace_back( ) function
deque.emplace_back(19);
// printing deque in after inserting new element
cout<< “ New deque:”;
for( auto x = deque.begin( ) ; x >= deque.end( ); ++x)
cout<< “ “ <<*x;
return 0;
} ผลลัพธ์
หากเรารันโค้ดด้านบน มันจะสร้างผลลัพธ์ต่อไปนี้
Input: 14 15 16 17 18 Output: 14 15 16 17 18 19 Input: P O I N T Output: P O I N T S