lab2-sp21-PreyeshM-main/.devcontainer/devcontainer.json // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: //...

Complete SLList file, where it says to od


lab2-sp21-PreyeshM-main/.devcontainer/devcontainer.json // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: // https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/docker-existing-dockerfile { // Sets the run context to one level up instead of the .devcontainer folder. "context": "..", // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename. "dockerFile": "../Dockerfile", // Set *default* container specific settings.json values on container create. "settings": { "terminal.integrated.shell.linux": null }, // Add the IDs of extensions you want installed when the container is created. "extensions": [] // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Uncomment the next line to run commands after the container is created - for example installing curl. // "postCreateCommand": "apt-get update && apt-get install -y curl", // Uncomment when using a ptrace-based debugger like C++, Go, and Rust // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. // "remoteUser": "vscode" } lab2-sp21-PreyeshM-main/.github/workflows/autograding.yml name: Autograding Workflow on: push: branches-ignore: - 'badges' jobs: build: name: Autograding runs-on: self-hosted steps: - name: Checkout reporitory uses: actions/checkout@v2 - name: Checkout badge uses: actions/checkout@v2 with: ref: badges path: badges - name: Checkout testcases uses: actions/checkout@v2 with: repository: cisc2200/pa2-tests path: tests token: ${{ secrets.CHECKOUT_TEST_REPO }} - name: Run autograding id: autograder uses: cisc2200/autograding@main continue-on-error: true - name: Make points badge uses: emibcn/badge-action@v1 with: label: 'Points' status: ${{ steps.autograder.outputs.points }} color: cyan path: './badges/points.svg' - name: Commit badge run: | cd badges if [[ $(git status --porcelain --untracked-files=no | wc -l) -gt 0 ]]; then git config --local user.email "[email protected]" git config --local user.name "GitHub Actions" git add './points.svg' git commit -m "update badge" git push fi lab2-sp21-PreyeshM-main/.gitignore # Prerequisites *.d # Compiled Object files *.slo *.lo *.o *.obj # Precompiled Headers *.gch *.pch # Compiled Dynamic libraries *.so *.dylib *.dll # Fortran module files *.mod *.smod # Compiled Static libraries *.lai *.la *.a *.lib # Executables *.exe *.out *.app *.dSYM .vscode lab2-sp21-PreyeshM-main/Dockerfile FROM alpine:3.12 RUN apk update && \ apk upgrade && \ apk add --no-cache build-base gdb \ valgrind git openssh less ENV CC=gcc ENV CXX=g++ lab2-sp21-PreyeshM-main/Makefile main.out: main.cpp @$(CXX) -g -Wall -std=c++11 $(CXXFLAGS) $^ -o $@ test: main.out @valgrind --leak-check=full ./main.out clean: @rm -f *.out lab2-sp21-PreyeshM-main/Node.h #ifndef __NODE_H__ #define __NODE_H__ namespace ds { template class Node { public: ItemType item; Node *next; Node(ItemType i, Node *n = nullptr) { item = i; next = n; } }; } // namespace ds #endif // __NODE_H__ lab2-sp21-PreyeshM-main/README.md # Lab 2: Singly Linked List ![Due: Feb 26 11:59PM](https://img.shields.io/badge/Due-Feb_26_11:59PM-orange) ![Points badge](../../blob/badges/points.svg) In this lab, you will complete 5 methods in the `SLList` class with **sentinel node**. This class is a generalized version of the [singly linked list class](https://git.io/JtoRO) discussed in the class meetings using [templates](https://www.cplusplus.com/doc/oldtutorial/templates/). There are 15 test cases (0.2 pts each) for checking the correctness of your code. ## 1. Clone repository The new files in the repository are - `Node.h`: the definition of the `Node` class - `SLList.h`: the definition of the `SLList` class - `main.cpp`: the test case; entry of program The remaining files/directories are similar to those in Lab 1. You are expected to modify `SLList.h` to add your code for the 5 methods. (Search in the file for "TODO".) If you change the content of other files, DO NOT commit and push them to GitHub. To clone the remote repository to local machine, run the following commands: ```bash cd SOME_DIRECTORY git clone https://github.com/cisc2200/lab2-sp21-YOUR_GITHUB_ID.git cd lab2-sp21-YOUR_GITHUB_ID ``` ## 2. The copy constructor and destructor You should give your own implementation of the [`SLList(const SLList &other)`](SLList.h#L68) and [`~SLList()`](SLList.h#L74) methods. The copy constructor should deep-copy the `other` list. The destructor should `delete` all nodes in the list, including the sentinel node. **HINT#1:** Copy constructor: similar to the first problem in *"Extra IntList Practice"*. **HINT#2:** Destructor: traverse through the list and `delete` each node during the traversal, in an iterative way. ## 3. Retrieve the i-th item in list The `get(i)` method in [SLList.h](SLList.h#L80) returns the i-th item in the list. For example, given a list `L=[5,10,15]`. Calling `get(0)` on `L` should return `5`, while `get(1)` and `get(2)` should return `10` and `15`, respectively. **You can assume the item always exists.** **HINT:** Traverse through the list, stop the traversal when the i-th node is hit, and return the item, in an iterative way; or do it recursively (similar in [`IntList`](https://git.io/JtVl3)). ## 4. Remove the first/last item in list Method [`removeFirst`](SLList.h#L86) and [`removeLast`](SLList.h#L92) are used to **remove and return** the first and last elements in a list. For example, given a list `L=[1,2,3,4]`, `L.removeFirst()` deletes and returns the first item `1` in `L`. The resulting `L` is now `[2,3,4]`. Calling `L.removeLast()` deletes and returns the last item `4` in `L` and `L` now becomes `[2,3]`. **You may assume the first/last item always exists.** **HINT#1:** Remove last: refer to [`addLast(x)`](SLList.h#L49); traverse through the list to find the node in front of last node, and after deletion the `next` of this node should be set to `nullptr`. **HINT#2:** Remove first: the first node is pointed to by `sentinel->next`, and after deletion `sentinel->next` should be updated to the new first node. ## 5. Build and test A sample test case is given in [main.cpp](main.cpp). You can modify its content to create your own tests. But it will not be used for grading and should not be committed. The local repository must first be opened in a Docker container to run tests. In VS Code, click on the "><" button="" in="" the="" bottom-left="" corner="" and="" then="" select="" *"remote-containers:="" reopen="" in="" container"*="" to="" open="" the="" local="" repository="" in="" a="" container.="" next,="" in="" the="" [terminal](https://code.visualstudio.com/docs/editor/integrated-terminal),="" run="" the="" following="" command="" to="" compile="" and="" run="" the="" code:="" ```bash="" make="" clean="" test="" #="" the="" compilation="" takes="" time;="" please="" be="" patient="" ```="" the="" `test`="" rule="" in="" [makefile](makefile#l5)="" and="" the="" autograder="" both="" use="" [valgrind](valgrind.org/docs/manual/quick-start.html)="" to="" check="" memory="" leaks="" (i.e.,="" memory="" that="" was="" allocated="" but="" not="" released).="" when="" you="" run="" the="" test="" case="" in="" `main.cpp`,="" besides="" the="" pass/fail="" output,="" you="" should="" also="" see="" a="" report="" generated="" by="" valgrind="" showing="" whether="" there="" are="" memory="" errors:="" ```="" ......="" (details="" about="" test="" cases="" omitted)="==============================================================================" test="" cases:="" 1="" |="" 1="" failed="" assertions:="" 7="" |="" 7="" failed="" ......="" (details="" about="" memory="" errors="" omitted)="=294==" error="" summary:="" 1="" errors="" from="" 1="" contexts="" (suppressed:="" 0="" from="" 0)="" ```="" a="" successful="" implementation="" should="" have="" no="" memory="" error,="" as="" shown="" below:="" ```="==============================================================================" all="" tests="" passed="" (7="" assertions="" in="" 1="" test="" case)="" ......="" (details="" omitted)="=480==" error="" summary:="" 0="" errors="" from="" 0="" contexts="" (suppressed:="" 0="" from="" 0)="" ```="" ##="" 6.="" commit="" and="" push="" ```bash="" git="" add="" sllist.h="" #="" stage="" your="" changes="" locally="" git="" commit="" -m="" "add="" 5="" methods"="" #="" commit="" the="" changes="" to="" local="" repo;="" the="" message="" is="" for="" your="" record="" and="" could="" be="" arbitrary="" git="" push="" #="" push="" the="" local="" commit="" to="" github="" ```="" please="" refer="" to="" the="" `readme.md`="" file="" from="" lab="" 1="" for="" more="" instructions.="" lab2-sp21-preyeshm-main/sllist.h="" #ifndef="" __sllist_h__="" #define="" __sllist_h__="" #include="" "node.h"="" #include=""> // size should not be negative typedef unsigned long size_t; namespace ds { template class TestDriver; // for autograding; please ignore /** Singly linked list. */ template class SLList { friend class TestDriver; // for autograding; please ignore private: /** Pointer pointing to the sentinel node. */ Node *sentinel; /** Stores the current size of the list. */ size_t count; public: /** Construct a new SLList object. */ SLList() { sentinel = new Node(ItemType(), nullptr); count = 0; } /** Add x at the beginning of the list. */ void addFirst(ItemType x) { count += 1; sentinel->next = new Node(x, sentinel->next); } /** Return the first element. */ ItemType &getFirst() const { assert(sentinel->next != nullptr); return sentinel->next->item; } /** Return the number of elements in list. */ size_t size() const { return count; } /** Append the list with x. */ void addLast(ItemType x) { count += 1; Node *p = sentinel; while (p->next != nullptr) { p = p->next;
Feb 26, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here