Write down the code of the following function of Link List Class. i) void removeFromHead() ii) int countDuplicate(int key) | PU | Past Paper 2017

UNIVERSITY OF THE PUNJAB

Fourth Semester 2017

Examination: B.S. 4 Years Programme 

Paper: Data Structure and Algorithm

Course Code: IT-207 / IT-22408

Long Questions

a) Write down the code of the following function of Link List Class.

i) void removeFromHead() //remove the first node at head

ii) int countDuplicate(int key) //count the node having duplicate values.

void removeFromHead()

void removeFromHead() {
 if(size>0){
  currentNode=headNode;
  currentNode=currentNode->getNext();
  headNode=currentNode;  
  size--;
 }else{
  cout<<"List is empty";
 }
}

int countDuplicate(int key)

int countDuplicate(int key){
 int count=0;
 node* ptr;
 ptr=headNode;
 do{
  if(ptr->get()==key){
   count++; 
  }
  ptr=ptr->getNext();
 }while(ptr!=NULL);
 return count;
}

Let me know in the comment section if you have any question.

Previous Post:
Write down the code for Insertion Sort | PU | Past Paper 2017


Comments