Question

Linked Lists implementation on Lists Executive Summary: Linked list implementation on lists includes two parts: Data part - stores an element of the list Next part- stores link/pointer to next element You are asked to implement Lists through Linked Lists to perform basic ADT functions. Project Objective: in completing this project, you will Enhance your ability to understand Lists Familiar with the idea of linked list Enable yourself to perform Linked Lists programming skills Due Dates and Honor: This project will be due by the beginning of the class on 7/16/2018. This is an independent programming project, and it is very important that you understand and abide by the policy concerning programming projects. Remember, your personal honor and integrity is far more important than your grade on the project. Detailed Specification: Understand and run the following code. Take a snapshot of the program output. 1. tincludeciostream> using namespace std: class node public: int data; node next: class PointerList
media%2F007%2F0073e096-e897-48cd-bcbc-34
media%2F108%2F108a6c50-be12-4249-8edf-31
media%2F42c%2F42c0099b-5404-4eef-a165-f5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

///modifying insert method

void insert(int preptr_value, int element)

{ //declaraing

//new node to insert

node *newptr = newnode;

newptr->data =element;

//finding position of preptr_value

if(top==NULL)//means preptr_value not in the list

{

cout<<"Error: "<<preptr_value<<" Not in the list\n";

}

else

{

//finding preptr_value position in list..

node *temp = top;

while(temp->next!=top)

{

if(temp->data==preptr_value)

{

break;//if position is found

}

}

if(temp==top)

{

if(top->data!=preptr_value)

cout<<"Error: "<<preptr_value<<" Not in the list\n";

else

{

newptr->next =top;

top = newptr;

}

}

else

{

//linking / inserting into list

newptr->next =temp->next;

temp->next = newptr;

}

}

}

//modifying remove method

void remove(int preptr_value)

{

//finding position of preptr_value

if(top==NULL)//means preptr_value not in the list

{

cout<<"Error: "<<preptr_value<<" Not in the list\n";

}

else

{

//finding preptr_value position in list..

node *temp = top;

while(temp->next!=top)

{

if(temp->data==preptr_value)

{

break;//if position is found

}

}

if(temp==top)

{

if(top->data!=preptr_value)

cout<<"Error: "<<preptr_value<<" Not in the list\n";

else

cout<<"Contains only one value...Deletion can't be done\n";

}

else

{

node *temp1 = temp->next;

temp->next= temp1->next;

delete(temp1);//deleting node..

}

}

}

Add a comment
Know the answer?
Add Answer to:
Linked Lists implementation on Lists Executive Summary: Linked list implementation on lists includes two parts: Data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Parts B is about our linked list implementation. avvut our linked list implementation. Recall that the...

    Parts B is about our linked list implementation. avvut our linked list implementation. Recall that the declaration of a list node is. class DListNode { public int key; public DistNode previous; public DListNode next; de ollos Salon You can assume that this is an inner class within the full MyLinked List class. B. Write a method that will add a new element to the front of a doubly linked list. Assume that head and tail point to the head and...

  • You are given the code for a singly linked list-based implementation of the List ADT. You...

    You are given the code for a singly linked list-based implementation of the List ADT. You will add a function called isUnique( ) to the List class such that the function will return true if all the integer elements in the List are unique and return false otherwise. The main function is written in such a way that it will create 1000 Lists (each of size listSize) of random integers in a range [1...maxValue] and will call the isUnique function...

  • c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream>...

    c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream> using namespace std; template<class T> struct Node {     T data;//data field     Node * next;//link field     Node(T data) {       this->data = data;     } }; template<class T> class linked_list{ private:       Node<T> *head,*current; public:       linked_list(){//constructor, empty linked list         head = NULL;         current = NULL;       }       ~linked_list(){         current = head;         while(current != NULL) {          ...

  • Using a doubly linked list as the underlying data structure, implement a list ADT that implements...

    Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...

  • Q) Modify the class Linked List below to make it a Doubly Linked List. Name your...

    Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...

  • C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use...

    C++ Linked List Implementation Motivation As we discussed in class, the data structures that you use to implement your program can have a profound impact on it's overall performance. A poorly written program will often need much more RAM and CPU time then a well-written implementation. One of the most basic data structure questions revolves around the difference between an array and a linked list. After you finish this assignment you should have a firm understanding of their operation. Problem...

  • Implement the stack queue data structure with a linked list implementation to get the given test...

    Implement the stack queue data structure with a linked list implementation to get the given test code in driver.cpp to work properly: driver.cpp code: #include <iostream> #include "stackLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout << "Popping: " << stk.pop() << endl; }...

  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for ...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT