Question

In: Computer Science

Can anyone make a documentation and comments for the following code? Documentation in doxgen format please....

Can anyone make a documentation and comments for the following code? Documentation in doxgen format please. Thank you!

And simple comments for the code. Thank s.

template <typename T>
bool LinkedList<T> :: search(const T& item) const
{
// if list is not empty display the items
Node<T>* current = first;
while (current != NULL)
{
if (current->info == item)
{
return true;
}
current = current->link;
}
return false;
}


template <typename T>
void LinkedList<T> :: deleteNode(const T& item)
{
Node<T>* current = first;
Node<T>* previous = NULL;
while (current != NULL)
{
if (current->info == item)
{
if (previous == NULL)
{
first = first->link;
}
else
{
previous->link = current->link;
if (previous->link == NULL)
{
last = previous;
}
}

free(current);
count--;
return;

}
previous = current;
current = current->link;
}
throw LinkedListItemNotFoundException();

}


template <typename T>
T& LinkedList<T> :: findItemAtIndex(int index)
{
int i = 0;
Node<T>* current = first;
while (current != NULL)
{
if (i == index)
{
return current->info;
}
current = current->link;
i++;
}
throw LinkedListItemNotFoundException();
}


template <typename T>
T& LinkedList<T> :: operator[](int index)
{
return findItemAtIndex(index);
}


template <typename T>
void LinkedList<T> :: deleteItemAtIndex(int index)
{
T item = findItemAtIndex(index);
deleteNode(item);
}

Solutions

Expert Solution

/************************************
*************************************
*Implementation of linked list
*Elements are stored in Node
*Contains all the function definitins
*of the linked list
*************************************
************************************/
//______________________________
//search an item in the linked list
//if item found then return true otherwise
//return false
template <typename T>
bool LinkedList<T> :: search(const T& item) const{
   // if list is not empty display the items
   //store the address of first in the temporary
   //variable current
   Node<T>* current = first;
   //linear search the entire linked list
   while (current != NULL){
       //item found
       if (current->info == item){
           return true;
       }
       current = current->link;
   }
   //item not found
   return false;
}
//______________________________

template <typename T>
void LinkedList<T> :: deleteNode(const T& item){
   //temporary variables for traversing
   Node<T>* current = first;
   Node<T>* previous = NULL;
   //linear search the entire linked list
   while (current != NULL){
       //item found
       if (current->info == item){
           //node to be deleted is the first node
           if (previous == NULL){
               first = first->link;
           }
           else{
               //node to be deleted is the intermediate node
               previous->link = current->link;
               //node to be deleted is the last node
               if (previous->link == NULL){
                   last = previous;
               }
           }
           //deallocate memory
           free(current);
           //decrease number of items
           count--;
           //return the control after successful deletion
           return;
       }
       //if item not found traverse linked list further
       previous = current;
       current = current->link;
   }
   //excption for item not found in linked list
   throw LinkedListItemNotFoundException();

}
//_____________________________________
//finds an item at a particular index
//return the reference of the item
template <typename T>
T& LinkedList<T> :: findItemAtIndex(int index){
   int i = 0;
   Node<T>* current = first;
   //traverse until the index is found
   while (current != NULL){
       //index found
       if (i == index){
           //return the item
           return current->info;
       }
       //item not found yet traverse further
       current = current->link;
       i++;
   }
   //excption for item not found in linked list
   throw LinkedListItemNotFoundException();
}
//______________________________
//overload [] opearator to access linked list using index
//like l[10]
template <typename T>
T& LinkedList<T> :: operator[](int index){
   //call the already written function findItemAtIndex(index)
   return findItemAtIndex(index);
}
//__________________________________
//delete an item at the particular index of the linked list
template <typename T>
void LinkedList<T> :: deleteItemAtIndex(int index){
   //get the reference of the item using already written function
   //findItemAtIndex(index)
   T item = findItemAtIndex(index);
   //deallocate memory
   deleteNode(item);
}
/***********************************************
*end of the function definitions of linked list
************************************************/


Related Solutions

Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Please can you explain to me how to do a clinical documentation using DAR Format? Using...
Please can you explain to me how to do a clinical documentation using DAR Format? Using this scenario: - You are assigned to Mrs. Jones for morning care. While assisting her with her morning bath you notice a purplish-blue bruise on her left hip. When you comment on it, she states that she fell yesterday when getting off the toilet, but didn’t tell anyone. She states the area is sore and moans when it is touched. Her mobility status stated...
In c++, Can anyone make these code int user input as user have to put all...
In c++, Can anyone make these code int user input as user have to put all the amount. int main()    {        Polygon p1(3,4,4.5,5.5);        Polygon p2(4,4,5.5,6.5);        Polygon p3(5,4,6.5,7.5);               cout<<"Area of Polygon#1:"<<p1.getArea()<<endl;        cout<<"Perimeter of Polygon#1:"<<p1.getPerimeter()<<endl;               cout<<"\nArea of Polygon#2:"<<p2.getArea()<<endl;        cout<<"Perimeter of Polygon#2:"<<p2.getPerimeter()<<endl;               cout<<"\nArea of Polygon#3:"<<p3.getArea()<<endl;        cout<<"Perimeter of Polygon#3:"<<p3.getPerimeter()<<endl;                         return 0;     ...
If anyone can please write a code for a 5x5 tic tac toe game in matlab...
If anyone can please write a code for a 5x5 tic tac toe game in matlab I would greatly appreciate it. Its extra credit. PLEASE HELP ME :(
please I don't understand this code. Can you put comments to explain the statements. Also, if...
please I don't understand this code. Can you put comments to explain the statements. Also, if there any way to rewrite this code to make it easier, that gonna help me a lot. import java.io.*; import java.util.*; public class State {    private int citi1x,citi1y; private int pop1; private int citi2x,citi2y; private int pop2; private int citi3x,citi3y; private int pop3; private int citi4x,citi4y; private int pop4; private int plantx,planty; public int getCity1X(){ return citi1x; } public int getCity1Y(){ return citi1y;...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate...
Java Code - Please explain each step through comments. Also, make sure Main (P3_13) is separate from your class BetterRectangle. Lastly, post a picture of your code inside an IDE along with your output. My code is below, needs modification. E9.13The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle ofthe Rectangle class that has getPerimeter and getArea methods. Do not add any instance...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you...
JAVA CODE, BEGINERS; Please use comments to explain For all of the following words, if you move the first letter to the end of the word, and then spell the result backwards, you will get the original word: banana dresser grammar potato revive uneven assess Write a program that reads a word and determines whether it has this property. Continue reading and testing words until you encounter the word quit. Treat uppercase letters as lowercase letters.
Please complete the following code in C using the comments as instructions. Further instructions are below...
Please complete the following code in C using the comments as instructions. Further instructions are below the code. challenge.c // goal: print the environment variables to the file "env.txt", one per line // (If envp is NULL, the file should be empty, opening in write mode will do that.) // example: // inputs: // envp/environ = {"E1=2","E2=7",NULL} // outputs: // env.txt as a string would be "E1=2\nE2=7\n" // example: // inputs: // envp/environ = {NULL} or NULL // outputs: //...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
Please do it in C++. Please comment on the code, and comments detail the run time...
Please do it in C++. Please comment on the code, and comments detail the run time in terms of total operations and Big O complexities. 1. Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase letters in an arbitrary order and uses that as the encoder for a cipher (that is, A is mapped to the first character of the parameter, B is mapped to the second, and so on.) Please derive the decoding...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT