Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is my assignment. I have to create a linked list that is accessed by a driv

ID: 3584813 • Letter: T

Question

This is my assignment. I have to create a linked list that is accessed by a driver program. I have read a lot about it, but I'm not sure what everything means in the skeleton code I have been given. Here it is, if you can help, I appreciate it. /* linked_list.cpp */ /* AUTHOR: WHAT: CSCI 2270 Assignment 1 COLLABORATORS: Web sites: http://www.cplusplus.com/forum/beginner/6459/ http://www.cplusplus.com/reference/list/list/ */ // include the header file that provides function prototypes and the // node structure. When you turn in your assignment, the grading // system will use its own copy of this file, so don't edit it, and // implement all the functions it specifies. #include "linked_list.h" // sstream gives you the stringstream object. Google it, and admire // how much easier this makes life. #include using namespace std; // your linked list implementation goes here :) //1. create a new node structure that points to NULL and holds the // provided integer. return a pointer to that new node. node* init_node(int data) { return NULL; // change this to return a newly initialized node. } //2. create a space-separated string representing the contents of the // list, in the same order they are found beginning from the head of // the list. return that string object. For example, this might // return "" (the empty string) if the list is empty, or it might // return "1 7 3" or "1 7 3 " (note the space at the end, you can have // that there and it is OK). std::string report(node* root) { return NULL; // change this to return a proper string, // even if it is a zero-length string object. } //3. insert an integer into the list pointed to by head. the resulting // list is one element longer, and the newly appended node has the // given data value. consider using the 'append' function to help. void append_data(node** head, int data) { // implement me } //4. this is the same as append_data, except we're adding a node, rather // than a value. void append(node** head, node* new_node) { // implement me } // 5. similar to append_data. insert a new node that contains the given // data value, such that the new node occupies the offset // indicated. Any nodes that were already in the list at that offset // and beyond are shifted down by one. For example if the list // contains 23, 74, 93, and we insert 42 at index 1, the resulting // list should be 23, 42, 74, 93. void insert_data(node** head, int offset, int data) { // implement me } //6. this is the same as insert_data, except we're inserting a node, // rather than a value. void insert(node** head, int offset, node* new_node) { // implement me } //7. remove the node indicated by the given offset. For example if our // list contains 23, 74, 93, and we remove offset 1, the resulting // list should then contain 23, 93. void remove(node** parent, int offset) { // implement me } //8. report the number of nodes in the linked list pointed to by head. int size(node* head) { return 0; // implement me } // 9. return true if the linked list pointed to by head contains a node // with the specified value. bool contains(node* head, int data) { return false; // implement me }

Explanation / Answer

@SuppressWarnings({ "rawtypes" }) public class LinkedList { protected static class Node { protected Comparable data; protected Node next; protected Node ( Comparable data ) { this.data = data; this.next = null; }// end constructor protected Node ( Comparable data, Node next ) { this.data = data; this.next = next; }// end constructor public void setData ( Comparable data ) { this.data = data; }// end setData public void setNext ( Node next ) { this.next = next; }// end setNext public Comparable getData () { return this.data; }// end getData public Node getNext () { return this.next; }// end getNext }// end Node class protected Node head = null; protected int size = 0; // Return the present size of the linked list public int size() { return size; }// end size public void addFirst(Comparable s) { Node newNode = new Node(s, head); head = newNode; size++; } public void addLast(Comparable node) { Node newNode = new Node(node); if(size == 0) { head = newNode; } else { Node curr = head; while(curr.next != null) { curr = curr.next; } curr.next = newNode; } size++; } public void add(Comparable string) { Node newNode = new Node(string); if (size == 0) { head = newNode; } else { Node curr = head; while (curr.next != null) { curr = curr.next; } curr.next = newNode; } size++; } /* public void clear() { head = null; size = 0; } public String toString() { String s = ""; if(head == null) { System.out.println("List is Empty!"); } else { for(Node curr = head; curr != null; curr = curr.next) { s = s + curr.data + " "; } } return s; } public void sort() { Node position; Node start; if(size > 0) { for(position = head; position != null; position = position.next) { Node smallest = position; for(start = position.next; start != null; start = start.next) { if((Integer)start.data < (Integer)smallest.data) { smallest = start; } } Comparable temp = position.data; position.data = smallest.data; smallest.data = temp; } } } public void reverse() { if(head == null) { System.out.println("The list is empty."); } reverse(head); } public void reverse(Node node) { if(node != null) { reverse(node.next); System.out.println(node.data); } } public void listEven() { for(Node curr = head; curr != null; curr = curr.next) { if((Integer)curr.data % 2 == 0) { System.out.println(curr.data); } } } public Node listEvery(int amt) { Node curr; for(curr = head; curr.next != null; curr = curr.next) { } return curr; } public boolean removeN(int contains) { Node prev = null; Node curr = head; while(curr != null) { if(curr.data.equals(contains)) { curr = curr.next; if(prev == null) prev = curr; else prev.next = curr; size--; return true; } else { prev = curr; curr = curr.next; } } return false; } */ }// end LinkedList class
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote