The goal of this assignment is to complete the linked list I

The goal of this assignment is to complete the linked list I made in class. You are to make the parts that I commented at the bottom of the code. Note that may encounter errors in the my code, you are expected to fix them as well.

http://pastebin.com/Dm5rWNyF

Solution

/*Here i change your code and remove unwanted lines and mistakes and solve each and every part as you provided to solve,it\'ll run for number*/
#include <cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> V;//it is used for finding the median
class CIntNode{
public:
int m_nData;
CIntNode* m_pNext;
};
CIntNode* head;//global variable which can be access from any function
float avnode=0;
float countt=0;
class CLinkedList {
public:
// add one node at the end of the link & we don\'t have to find the depth if adding at depth just follow the code you will got it
void AddNode (int nData) {
CIntNode* temp=head;
if(temp==NULL){
CIntNode* pNew = new CIntNode();
pNew->m_nData=nData;
pNew->m_pNext=NULL;
temp=pNew;
head=temp;
return;
}
while(temp->m_pNext!=NULL){
temp=temp->m_pNext;
}
CIntNode* pNew = new CIntNode();
pNew->m_nData=nData;
pNew->m_pNext=NULL;
temp->m_pNext=pNew;
return;
}
void DeleteNode(int nkey) //delete a node of value nkey
{
CIntNode* temp=head;
CIntNode* current;
if(temp->m_nData==nkey)
{
head=temp->m_pNext;
delete temp;
return;
}
while(temp->m_pNext!=NULL){
if(temp->m_pNext->m_nData==nkey)
{
current=temp->m_pNext;
temp->m_pNext=temp->m_pNext->m_pNext;
delete current;
break;
}
temp=temp->m_pNext;
}
return;

}
// this will print the all node as int the list
void printNode(){
CIntNode* temp=head;
while(temp!=NULL){
avnode+=temp->m_nData;countt=countt+1;
V.push_back(temp->m_nData);
cout<<temp->m_nData<<\" \";//you can use printf(\"%d \",temp->m_nData);
temp=temp->m_pNext;
}
}
};

int main (int argc, char* argv)
{
CLinkedList list;
head=NULL;
list.AddNode (5);
list.AddNode (6);
list.AddNode (7);
list.DeleteNode(5);
list.AddNode (2);
list.AddNode (1);
list.AddNode (9);
list.AddNode (10);
list.DeleteNode(2);
cout<<\"list is\ \";
list.printNode();//print node function
sort(V.begin(),V.end());//using vector for finding the median of the node value
if(V.size()%2==0)
{
cout<<endl<<\"median is:\"<<(V[V.size()/2-1]+V[V.size()/2])/2;//if total node is even
}
else
cout<<endl<<\"median is:\"<<V[V.size()/2];//if total node is even,you can use printf command here too
cout<<endl<<\"average node value:\"<<avnode/countt;//average value node value

return 0;

}

The goal of this assignment is to complete the linked list I made in class. You are to make the parts that I commented at the bottom of the code. Note that may
The goal of this assignment is to complete the linked list I made in class. You are to make the parts that I commented at the bottom of the code. Note that may

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site