Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Unsorted Linked list in c++

UnsortedList::UnsortedList()
{
    length = 0;
    data = NULL;
    currentPos = NULL;
}

bool UnsortedList:: IsEmpty(){
    if(length == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool UnsortedList::IsFull(){
    Node* ptr = new Node();
    if(ptr == NULL)
      return true;
    else
    {
      delete ptr;
      return false;
    }
}

void UnsortedList::ResetList(){
   currentPos = NULL;
}

void UnsortedList::MakeEmpty()
{
   Node* tempPtr = new Node();

   while(data != NULL)
   {
     tempPtr = data;
     data = data->next;
     delete tempPtr;
   }
   length = 0;
}

int UnsortedList::LengthIs(){
    return length;
}

bool UnsortedList:: IsInTheList(float item){

Node* location = new Node();
location = data;
bool found = false;

while(location != NULL && !found)
{
    if(item == location->element)
        found = true;
    else
        location = location->next;
}
   return found;
}

void UnsortedList:: InsertItem(float item){

    Node* location = new Node();
    location->element = item;
    location->next=data;
    data = location;
    length++;
}

void UnsortedList:: DeleteItem(float item){

Node* location = data;
Node* tempPtr;

if(item == data->element){
    tempPtr = location;
    data = data->next;
}
else{
  while(!(item == (location->next) ->element) )
    location = location->next;
    tempPtr = location->next;
    location->next = (location->next)->next;
}
  delete tempPtr;
  length--;
}

float UnsortedList::GetNextItem(){
   if(currentPos == NULL)
    currentPos = data;
   else
    currentPos = currentPos->next;
   return currentPos->element;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ ros publisher 
Cpp :: qt popup window 
Cpp :: std distance c++ 
Cpp :: C++ convert integer to digits, as vector 
Cpp :: if even number c++ 
Cpp :: check if float has decimals c++ 
Cpp :: return by reference in cpp 
Cpp :: how to clear console c++ 
Cpp :: parallelize for loop c++ 
Cpp :: c++ read image opencv in folder 
Cpp :: C++ switch - case - break 
Cpp :: array and for loop in c++ 
Cpp :: cpp unions 
Cpp :: C++ Find the sum of first n Natural Numbers 
Cpp :: matplotlib hide numbers on axis 
Cpp :: getline cpp 
Cpp :: file open cpp 
Cpp :: c++ random number between 0 and 1 
Cpp :: c++ cout colored output xcode 
Cpp :: why are inline keyword in header c++ 
Cpp :: c++ print string 
Cpp :: c++ vector move element to front 
Cpp :: struct and pointer c++ 
Cpp :: delete dynamic array c++ 
Cpp :: 2d array c++ 
Cpp :: how to split string in c++ 
Cpp :: int to float c++ 
Cpp :: how to declare a 2D vector in c++ of size m*n with value 0 
Cpp :: string split by space c++ 
Cpp :: sort vector of strings 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =