This function returns (a copy of) the element at the head of the
list, assuming the list is not empty. Otherwise, we should
return None to indicate the list is empty.
This method removes and returns the first element of the list.
Be careful to consider how to handle the case where this node is
shared amongst other lists.
This method adds an element to the head end of the list. Be
careful to consider the case where other lists may be sharing any
preexisting head node. Pushing to this list must not modify any
sister lists that share other nodes. We return nothing.
When in a large battle with the rest of The Avengers, its
important to quickly check on the health and status of ones armor.
Stark wants to add a new feature to his suit that allows him to
quickly determine if his suit if battle ready.
You may implement list traversal in order to
complete this section, but it isn't necessary. Notice that Lists
may be cloned without cloning the data inside
(ie, lists may share nodes).
Is compatible checks if the versions of the various armor pieces
match the version of the suit. For example, a suit with version 6
should have parts of version 6.
This method is a bit tricky. Its the only one that modifies data
inside lists. All armor pieces of components
with 2 fields (damage and power level) should be
restored to 100 power and made undamaged. You should only modify
the armor if and only if the damaged field is true. Armor pieces
that are not damaged, but have low power level should remain
unmodified.
1 2 3 4 use std::{ borrow:: BorrowMut, ops: :{Deref, DerefMut}, sync::{Arc, RwLock}, }; 5 6 7 8 9 10 11 12 13 14 15 16 17 #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Component { Helmet(bool), //is damaged? LeftThrusters(bool, i32), //is damaged? How much power left? RightThrusters(bool, i32), //is damaged? How much power left? LeftRepulsor (bool, i32), //is damaged? How much power left? RightRepulsor(bool, i32), 1/is damaged? How much power left? ChestPiece(bool, i32), //is damaged? How much power left? Missiles(i32), //how many missiles left? ArcReactor(i32), // How much power left? Wifi(bool), // connected to wifi? } 18 19 20 21 22 #[derive(Debug, clone, Copy, Partiale, Eq)] pub struct Armor { pub component: Component, pub version: i32, } 23 24 25 26 // Part 2 27 28 // Students should fill in the Link type themselves. The Node and List types are given as is. 29 type Link = (Empty | Component); po
30 31 32 33 struct Node { data: Armor, rest: Link, } 34 35 36 37 38 #[derive(Clone)] pub struct List { head_link: Link, size: usize, } 39 40 41 42 43 impl List { pub fn new() -> Self { unimplemented! () } 44 45 四89899m && 如如如幻B9%BBBBB 46 47 48 pub fn size(&self) -> usize { self.size } 49 50 51 52 pub fn peek(&self) -> Option<Armor> { unimplemented!() } 53 54 55 56 pub fn push(&mut self, component: Armor) { unimplemented!() } 57
58 59 60 pub fn pop(&mut self) -> Option<Armor> { unimplemented!() } 61 62 } 63 64 // Part 3 65 66 67 #[ derive(Clone)] pub struct Suit { pub armor: List, pub version: i32, } 69 70 71 72 73 68822乃乃形刀四四%a impl Suit { pub fn is_compatible(&self) -> bool { unimplemented!() } 74 75 76 77 78 pub fn repair(&mut self) { unimplemented ! ( ) } 79 80 } 81
This function returns (a copy of) the element at the head of the list, assuming the list is not empty. Otherwise, we sho
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
This function returns (a copy of) the element at the head of the list, assuming the list is not empty. Otherwise, we sho
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!