Check return value when peeking linked lists
This commit is contained in:
		
							parent
							
								
									60b4042681
								
							
						
					
					
						commit
						6b8435d5f6
					
				@ -187,7 +187,8 @@ int CircleDoubleList::peek() const
 | 
			
		||||
  if (!isEmpty())
 | 
			
		||||
    std::cout << "[" << tail->next->data << "] is at the top of our list\n";
 | 
			
		||||
  else std::cout << "Nothing to peek, our list is empty...\n";
 | 
			
		||||
  return tail->data;
 | 
			
		||||
  // If the list has data we return it, otherwise we return the smallest possible int (error)
 | 
			
		||||
  return (!isEmpty()) ? tail->data : INT32_MIN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** print
 | 
			
		||||
 | 
			
		||||
@ -191,7 +191,8 @@ int CircleSingleList::peek() const
 | 
			
		||||
  if (!isEmpty())
 | 
			
		||||
    std::cout << "[" << tail->next->data << "] is at the top of our list\n";
 | 
			
		||||
  else std::cout << "Nothing to peek, our list is empty...\n";
 | 
			
		||||
  return tail->next->data;
 | 
			
		||||
  // If the list has data we return it, otherwise we return the smallest possible int (error)
 | 
			
		||||
  return (!isEmpty()) ? tail->next->data : INT32_MIN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** print
 | 
			
		||||
 | 
			
		||||
@ -168,7 +168,8 @@ int DoubleList::peek() const
 | 
			
		||||
  if (!isEmpty())
 | 
			
		||||
    std::cout << "[" << head->data << "] is at the top of our list\n";
 | 
			
		||||
  else std::cout << "Nothing to peek, our list is empty...\n";
 | 
			
		||||
  return head->data;
 | 
			
		||||
  // If the list has data we return it, otherwise we return the smallest possible int (error)
 | 
			
		||||
  return (!isEmpty()) ? head->data : INT32_MIN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** print
 | 
			
		||||
 | 
			
		||||
@ -168,7 +168,8 @@ int SingleList::peek() const
 | 
			
		||||
  if (!isEmpty())
 | 
			
		||||
    std::cout << "[" << head->data << "] is at the top of our list\n";
 | 
			
		||||
  else std::cout << "Nothing to peek, our list is empty...\n";
 | 
			
		||||
  return head->data;
 | 
			
		||||
  // If the list has data we return it, otherwise we return the smallest possible int (error)
 | 
			
		||||
  return (!isEmpty()) ? head->data : INT32_MIN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** print
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user