ADVERTISEMENT
ADVERTISEMENT

Rust program to perform the POP operation

Rust | Vector Example: Write a program to perform the POP operation.
Submitted by Nidhi, on October 23, 2021

Problem Solution:

In this program, we will create a vector to store the name of countries then we will perform PUSH and POP operations.

Program/Source Code:

The source code to perform the POP operation is given below. The given program is compiled and executed successfully.

// Rust program to perform POP operation

fn main() {
   let mut countries = vec!["INDIA","USA"];
   
   countries.push("UK");
   countries.push("CANADA");
   countries.push("ENGLAND");
   
   println!("Countries are:\n{:?}", countries);
   
   countries.pop();
   countries.pop();
   
   println!("\nCountries after POP operation:\n{:?}", countries);
}

Output:

Countries are:
["INDIA", "USA", "UK", "CANADA", "ENGLAND"]

Countries after POP operation:
["INDIA", "USA", "UK"]

Explanation:

Here, we created a vector to store the name of countries, and then we performed a PUSH operation to add the item into the vector and performed the POP operation to remove the item from the vector.

Rust Vectors Programs »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.