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

Please post code in format that can be copied. If possible please explain code but not...
Please post code in format that can be copied. If possible please explain code but not necessary. Directions: 1. Create a new project for the lab and copy stat.h, stat.cpp, and teststat.cpp into your workspace. 2. Now review the header file. Make sure you understand the design. Can you explain the difference between what the class represents versus how it plans to accomplish it? 3. Now edit the stat.cpp file. Notice that many of the member functions are missing. For...
Can someone please complete the following code(Java). The stuff in comments are the things you need...
Can someone please complete the following code(Java). The stuff in comments are the things you need to look at and code that package mini2; import static mini2.State.*; /** * Utility class containing the key algorithms for moves in the * a yet-to-be-determined game. */ public class PearlUtil { private PearlUtil() { // disable instantiation } /**    * Replaces all PEARL states with EMPTY state between indices    * start and end, inclusive.    * @param states    * any...
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;     ...
Please do in java with code available for copy and with comments so I can follow...
Please do in java with code available for copy and with comments so I can follow along :)\ Develop a program that prints out the sum of each column of a two-dimensional array. The program defines method sumColumn() takes a two-dimensional array of integers and returns a single-dimensional array that stores the sum of columns of the passed array. The program main method prompts the user to enter a 3-by-4 array, prints out the array, and then calls method sumColumns()....
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 :(
I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS ....
I want a unique c++ code for the following. PLEASE HIGHLIGHT THESE FUNCTIONS WITH COMMENTS . Add the following functions to the class arrayListType: Then, update the main function to test these new functions. removeAll - which removes ALL of the instances of a value in the list min - which returns the minimum value in the list max - which returns the maximum value in the list arrayListType.h : #ifndef H_arrayListType #define H_arrayListType class arrayListType { public: bool isEmpty()...
Please convert This java Code to C# (.cs) Please make sure the code can run and...
Please convert This java Code to C# (.cs) Please make sure the code can run and show the output Thank you! Let me know if you need more information. Intructions For this assignment you will be creating two classes, an interface, and a driver program: Class Calculator will implement the interface CalcOps o As such it will implement hexToDec() - a method to convert from Hexadecimal to Decimal. Class HexCalc will inherit from Calculator. Interface CalcOps will have abstract methods...
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;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT