Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

454 exercise6 #467

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Error404 from './pages/Error404';
import Exercise1 from './pages/Exercise1';
import Exercise2 from './pages/Exercise2';
import Exercise3 from './pages/Exercise3';
import Exercise6 from './pages/Exercise6';
import Home from './pages/Home';
import Lesson1 from './pages/Lesson1';
import Lesson10 from './pages/Lesson10';
Expand Down Expand Up @@ -42,6 +43,7 @@ function App(): JSX.Element {
<Route path="/exercise-1" element={<Exercise1 />} />
<Route path="/exercise-2" element={<Exercise2 />} />
<Route path="/exercise-3" element={<Exercise3 />} />
<Route path="/exercise-6" element={<Exercise6 />} />
<Route path="/conclusion" element={<Conclusion />} />
<Route path="*" element={<Error404 />} />
</Routes>
Expand Down
4 changes: 3 additions & 1 deletion src/components/SelectCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ const SelectCode: React.FC<SelectCodeProps> = ({ choices, handleClick }) => {
className="menu-item"
sx={{ whiteSpace: 'normal', wordWrap: 'break-word' }}
>
{choice}
<pre>
<code>{choice}</code>
</pre>
</MenuItem>
))}
</Select>
Expand Down
34 changes: 34 additions & 0 deletions src/pages/Exercise6.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FC } from 'react';
import '../styles/Exercise6.scss';
import RunCode from '../components/RunCode';

const question = [
{
options: [
'head = new Node();\nhead->next = new Node();\nhead->next = head;\ntail = head->next;',
'head = new Node();\nhead->next = new Node();\nhead->next = head;\ntail = head->next;',
'*head = new Node();\n*(head->next) = new Node();\n*(head->next->prev) = *head;\ntail = *head->next;',
'head = new Node();\nhead-> next = new Node();\ntail = head->next;\nhead->next->prev = head;',
],
answer:
'head = new Node();\nhead-> next = new Node();\ntail = head->next;\nhead->next->prev = head;',
correctText:
'Correct! Let’s go through this line by line. The first line creates a new node and assigns head to point to it. The second line creates a second node and assigns the head node’s next pointer to point to it. The third line assigns tail to point at the second node, since it copies the head node’s next pointer. The fourth line actually simplifies to tail->prev = *head, since from the third line we know tail = head->next, it assigns the previous pointer of the tail node to point back to the head node.',
wrongText: 'Not quite',
},
];

const Exercise6: FC = () => {
return (
<div className="exercise6-div">
<RunCode
questions={question}
displayText={
'Which code segment correctly starts the linked list?\n Node* head; // head Node, assume Node class is defined\nNode* tail; // tail Node'
}
/>
</div>
);
};

export default Exercise6;
4 changes: 4 additions & 0 deletions src/styles/Exercise6.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.exercise6-div {
white-space: pre-wrap;
word-break: break-all;
}
2 changes: 1 addition & 1 deletion src/styles/SelectCode.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
border: 1px;
border-color: #cfcfcf;
font-size: 1.6vw;
height: 5vh;
height: fit-content;
width: fit-content;

@media (max-width: 600px) {
Expand Down
Loading