Recent Posts

Pages: 1 ... 8 9 [10]
91
Now a timed test program so that you can easily compare sorting times ...


Code: [Select]
// 6sorts_timed_all_auto_version.cpp //  // revised: 2017-02-13 //
 

#include "DLLinsertSorted.h"

// include <iostream> // included above //

#include <string>
#include <cstdlib>  // re, rand, srand
#include <ctime>    // re, time clock
#include <climits>  // re. RAND_MAX
#include <cctype>   // re. tolower
#include <cmath>    // re. log

#include <list>     // to compare c++ library 'list sort' times with 'list sort' times //


const int MAX_PRINT = 11;
const int MAX_NxN = 30000;


// 3 utilities to ease coding here ...
template< typename T >
T takeIn( const std::string& msg, const std::string& errMsg = "\nError! Try again.\n\n" )
{
    T val = T();
    while( true )
    {
        std::cout << msg;
        if( std::cin >> val && std::cin.get() == '\n' )
            break;
        else
        {
            std::cout << errMsg;
            std::cin.clear(); // clear error flasgs
            std::cin.sync(); // 'flush' cin stream ...
        }
    }
    return val;
}
char takeInChr( const std::string& msg )
{
    std::cout << msg;
    std::string reply;
    getline( std::cin, reply );
    if( reply.size() )
return reply[0];
    // else ...
    return 0;
}
bool more( const std::string& text = "" )
{
    char reply = takeInChr( "More " + text + "(y/n) ? " );
    if( reply == 'n' || reply == 'N' )
return false;
    // else ...
    return true;
}


// get a List of random ints in range 0..MAX_RAND
void fillUpList( List< int >& lst, int num )
{
    std::cout << "RAND_MIN = " << 0 << ", RAND_MAX = " << RAND_MAX << '\n';
    for( int i = 0; i < num; ++ i )
        lst.push_back( rand() );
}

template < typename T >
std::ostream& operator << ( std::ostream& os, const List< T >& lst )
{
    typename List< T >::const_iterator it;
    for( it = lst.begin(); it != lst.end(); ++ it ) os << *it << ' ';
    return os;
}




int main()
{
    using std::cout; using std::cin;
    using std::string;
   
    srand( time(0) ); // seed the random generator //
   
    do
    {
        int num = 0;
        for( ; ; )
        {
            num = takeIn< int >( "How many numbers to sort (10..2000000): " );
            if( num >= 10 && num <= 2000000 ) break;
            //else ///
            cout << "\nTry again with a value in range 10..2000000 ...\n\n";
        }
       
        List< int > lstCpy;
        fillUpList( lstCpy, num );
       
        List< int > lst;
        List< int >::const_iterator cit;
        double dt, t1, k;

        if( num <= MAX_NxN )
        {
            lst = lstCpy; // get from a copy //
            t1 = clock();
            lst.insert_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;
            cout << "\nTime to insert_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
           
            // t = k*n*n;
            // k = t/n/n
            k = dt/num/num;
           
            lst = lstCpy;
            for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
                lst.push_back( *cit );
            // Now size is doubled //
           
            t1 = clock();
            lst.insert_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;
            cout << "\nTime to insert_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
            cout << " Expected: " << 4*k*num*num << '\n';
                 

             

            lst.clear();
            t1 = clock();
            for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
                lst.insert_sorted( *cit );
            dt = (clock() - t1)/CLOCKS_PER_SEC;
            cout << "\nTime to insert_sorted was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
                 
            k = dt/num/num;

            lst.clear();
            for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
                lst.insert_sorted( *cit );
            for( cit = lstCpy.begin(); cit != lstCpy.end(); cit ++ ) // test POST ++ //
                lst.insert_sorted( *cit );
            // Now size is doubled //
     
            dt = (clock() - t1)/CLOCKS_PER_SEC;
           
            cout << "\nTime to insert_sorted was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
            cout << " Expected: " << 4*k*num*num << '\n';

                 
                 
                 
                 
            lst = lstCpy; // restore from copy //
            t1 = clock();
            lst.select_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;
            cout << "\nTime to select_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
                 
            k = dt/num/num;

            lst = lstCpy; // restore from copy //
            for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
                lst.push_back( *cit );
            // Now size is doubled //
            t1 = clock();
            lst.select_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;
           
            cout << "\nTime to select_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
            cout << " Expected: " << 4*k*num*num << '\n';



            lst = lstCpy; // restore from copy //
            t1 = clock();
            lst.bubble_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;
            cout << "\nTime to bubble_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
                 
            k = dt/num/num;

            lst = lstCpy; // restore from copy //
            for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
                lst.push_back( *cit );
            // Now size is doubled //
            t1 = clock();
            lst.bubble_sort();
            dt = (clock() - t1)/CLOCKS_PER_SEC;

            cout << "\nTime to bubble_sort was " << dt << " seconds "
                 << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
            cout << " Expected: " << 4*k*num*num << '\n';
         }
             



        lst = lstCpy; // restore from copy //
        if( num <= MAX_PRINT ) cout << "\nUnsorted: " << lst << '\n';
        t1 = clock();
        lst.merge_sort();
        dt = (clock() - t1)/CLOCKS_PER_SEC;
        cout << "\nTime to merge_sort was " << dt<< " seconds "
             << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
             
        if( num <= MAX_PRINT )
        {
            cout << "\nSorted  : " << lst << "\nReversed: ";
            lst.printReversed();
            cout << '\n';
        }
       
        // t = k*n*log(n)
        // k = t/n*/log(n)
       
        k = dt/num/log(num);

        lst = lstCpy; // restore from copy //
        for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
            lst.push_back( *cit );
        // Now size is doubled //
        t1 = clock();
        lst.merge_sort();
        dt = (clock() - t1)/CLOCKS_PER_SEC;

        cout << "\nTime to merge_sort was " << dt << " seconds "
             << ( lst.isSorted() ? "and SORTED ok." : "but was NOT sorted!" );
        cout << " Expected: " << k*2*num*log(2*num) << '\n';



             
        // compare with C++ library list ...
        std::list< int > cppLst;
        for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
            cppLst.push_back( *cit );
        t1 = clock();
        cppLst.sort();
        dt = (clock() - t1)/CLOCKS_PER_SEC;
        cout << "\nC++ library list sort was " << dt << " seconds.";
       
       
        k = dt/num/log(num);

        cppLst.clear();
        for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
            cppLst.push_back( *cit );
        for( cit = lstCpy.begin(); cit != lstCpy.end(); ++ cit )
            cppLst.push_back( *cit );
        // Now size is doubled //
        t1 = clock();
        cppLst.sort();
        dt = (clock() - t1)/CLOCKS_PER_SEC;

        cout << "\nC++ library list sort was " << dt << " seconds.";
        cout << " Expected: " << k*2*num*log(2*num) << '\n';
       

        cout << '\n';
    }
    while( more() );
}
92
And now ...

some timed testing of various sorts on a fairly full featured DLL ...


Firstly, the file with the relevant DLL ...

Code: [Select]
// DLLinsertSorted.h //  // revised: 2017-02-13 //

#ifndef DDL_INSERT_SORTED_H
#define DDL_INSERT_SORTED_H

#include <iostream>

template < typename T >
class List
{
    // forward declaration ... so can use inside nested iterator class //
    struct Node;   

public:
    // ctor...
    List() : head(0), tail(0), len(0) {}
   
    //dtor...
    ~List() { clear(); }
   
    void clear()
    {
        Node* del;
        while( head )
        {
            del = head;
            head = head->next;
            delete del;
        }
        tail = 0;
        len = 0;
    }

    // copy ctor...
    List ( const List& other )
    {
        head = tail = 0;
        len = 0;
        for( Node* cur = other.head; cur != 0; cur = cur->next )
            push_back( cur->data );
    }
   
    // overloaded operator =   (the assignment operator) //
    List& operator = ( const List& other )
    {
        if( this != &other )
        {
            clear();
            for( Node* cur = other.head; cur != 0; cur = cur->next )
                push_back( cur->data );
        }
        return *this;
    }
   
   
    size_t size() const { return len; }

    void push_front( const T& data )
    {
        Node* nNode = new Node( data );

        if( len )
        {
            nNode->next = head; // N->H
            head->prev = nNode; // N<-H
            head = nNode;
        }
        else tail = head = nNode;
        ++len;
    }
    void push_back( const T& data )
    {
        Node* nNode = new Node( data );

        if( len )
        {
            tail->next = nNode; // T->N
            nNode->prev = tail; // T<-N
            tail = nNode;
        }
        else tail = head = nNode;
        ++len;
    }
   
   
   
    // (forward iterators) now added here ...
    // so can easily access elements ...
    // and here ... to ease testing of BOTH insert sorted methods //
   
    class iterator
    {
        Node* ptr;
       
    public:
        // ctor(s) ...
        iterator( Node* ptr=0 ) : ptr(ptr) {}
       
        iterator& operator ++ ()     { ptr = ptr->next; return *this; }
        // Note that you canNOT update via this as a COPY returned //
        iterator operator ++ ( int ) { iterator cpy(*this); ptr = ptr->next; return cpy; }
       
        bool operator != ( const iterator& it ) const { return  ptr != it.ptr; }
        bool operator == ( const iterator& it ) const { return  ptr == it.ptr; }
       
        const T& operator * () const  { return ptr->data; }
        T& operator * ()              { return ptr->data; }
       
        const T* operator -> () const { return &ptr->data; }
        T* operator -> ()             { return &ptr->data; }
    } ;

    iterator begin() { return iterator(head); }
    iterator end()   { return iterator(0); }
   
    typedef iterator const_iterator;

    const_iterator begin() const { return iterator(head); }
    const_iterator end() const   { return iterator(0); }

   
   
    void insert_sorted( const T& data )
    {
        Node* nNode = new Node( data );

        // case 1 ... NOT inserted as the head node
        if( head  &&  head->data <= data )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur && cur->data <= data )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;
            nNode->prev = prev;

            if( cur ) // NOT at end
            {
                cur->prev = nNode;
                nNode->next = cur;
            }
            else // at end
            {
                tail = nNode;
            }
        }
        else // insert at head ...
        {
            if( len )
            {
                nNode->next = head;
                head->prev = nNode;
                head = nNode;
            }
            else tail = head = nNode;
        }

        ++ len;
    }
   
    void insert_sort() // uses power of DLL //
    {
        if( len > 1 )
        {
            Node* cur = head->next;
           
            // start with set of just the first 2 elements (if exists) //
            for( ; cur != 0; cur = cur->next )
            {
                // get copy of this new cmp element on each outer loop //
                T cmp = cur->data;
                // get Node of element just to the left of the above 'cmp'
                // to start the comparisons //
                Node* prev = cur->prev;
                while( prev != 0 && cmp < prev->data )
                {
                    // copy element 'up' to open up 'insertion-hole' //
                    prev->next->data = prev->data;
                    // 'decrement' in preparation for next inner loop //
                    prev = prev->prev;
                }
                // insert element at prev->next (since prev was 'decremented' above) //
                if( prev ) prev->next->data = cmp;
                else head->data = cmp;
            }
        }
    }

    void select_sort()
    {
        Node* cur = head;
        while( cur )
        {
            Node* min = cur;
            Node* next = cur->next;
            while( next )
            {
                if( next->data < min->data ) min = next; // update if needed //
                next = next->next;
            }
           
            if( cur != min ) // swap min and cur //
            {
                T tmp = cur->data;
                cur->data = min->data;
                min->data = tmp;
            }
           
            cur = cur->next;
        }
    }

    void bubble_sort()
    {
        if( len > 1 )
        {
            Node* cur = head->next; // start 1 element in //
            int size = len;
            bool swap;
            do
            {
                swap = false;
                // added to speed up the bubble-up to *each decreasing new* top //
                int i = 0;
                //while( cur != 0 )
                // added to speed up the bubble-up to *each decreasing new* top //
                while( ++i < size )
                {
                    if( cur->data < cur->prev->data ) // swap //
                    {
                        T tmp = cur->data;
                        cur->data = cur->prev->data;
                        cur->prev->data = tmp;
                        swap = true;
                    }
                    cur = cur->next;
                }
                --size;
                // get ready ready for next outer (do) loop //
                cur = head->next;
            }
            while( swap );
            //while( size > 1 );
        }
    }
   
   

    // merge sort the whole list in place (a 'divide and sort' recursive sort) //
    void merge_sort()
    {
        Node* p = head;
        merge_sort( p, len ); // p is updated in recursion using pass by ref.
        set_head_tail( p );
    }
   
   
    // 3 utilities used for testing //
    void print( std::ostream& os = std::cout ) const
    {
        Node* cur = head;
        while( cur )
        {
            os << cur->data << ' ';
            cur = cur->next;
        }
    }
    void printReversed( std::ostream& os = std::cout ) const
    {
        Node* cur = tail;
        while( cur )
        {
            os << cur->data << ' ';
            cur = cur->prev;
        }
    }
    bool isSorted() const
    {
        if( len > 1 )
        {
            Node* cur = head;
            while( cur->next )
            {
                if( cur->next->data < cur->data ) return false;
                cur = cur->next;
            }
        }
        return true;
    }
   

private:
   
    struct Node
    {
        T data;
        Node* prev;
        Node* next;
       
        // ctor...
        Node( const T& data = T() ) : data(data), prev(0), next(0) {}
    } ;

    Node* head;
    Node* tail;
    size_t len;
   
   
    // defined below class ...
    void merge_sort( Node*& head, int len ); // returns updated head by ref.

    // merge two sorted lists with heads 'a' and 'b' ... in sorted order
    Node* merge( Node* a, Node* b )
    {
        if( a == 0 ) return b;
        if( b == 0 ) return a;

        Node* sorted;  // now get appropriate new head for merged list
        if( a->data <= b->data )
        {
            sorted = a;
            a = a->next;
        }
        else
        {
            sorted = b;
            b = b->next;
        }

        Node* new_merged_head = sorted;

        // now merge lists ...
        while( a != 0 && b != 0 )
        {
            if( a->data <= b->data )
            {
                sorted->next = a;
                sorted = sorted->next;
                a = a->next;
            }
            else
            {
                sorted->next = b;
                sorted = sorted->next;
                b = b->next;
            }
        }

        // now ... append the ONE part that might have been left-over above ...
        if( a != 0 )
            sorted->next = a;
        else if( b != 0 )
            sorted->next = b;

        return new_merged_head;
    }

    void update()
    {
        tail = head;
        if( tail == 0 ) return;
        Node* prev = 0;
        while( tail->next != 0 )
        {
            prev = tail;
            tail = tail->next;
            tail->prev = prev;
        }
        head->prev = 0;
    }

    void set_head_tail( Node* p ) { head = p; update(); }
   
} ;
   


/////////////////// BEGIN MERGE SORT ///////////////////////
// divide list into two halves and then recursively sort each half ...
// then merge the two sorted halves using the above merge function
// Note: calling 'head' is updated by using 'pass by ref'

template < typename T >
void List< T >::merge_sort( Node*& p1, int len )
{
    if( len < 2 ) return;

    Node* pHead2;
    Node* pEnd1;

    int size2 = len/2;
    int size1 = len - size2;

    // split the list into two lists ... the first half begins with head
    pEnd1 = p1; // first set pEnd1 to the head address ...
    for( int i = 1; i < size1; ++i )
        pEnd1 = pEnd1->next;

    pHead2 = pEnd1->next; // second half begins with pHead2
    pEnd1->next = 0; // breaking the chain here... so we can have two lists

    // merge the lists after recusively merge_sorting them
    merge_sort( p1, size1 );
    merge_sort( pHead2, size2 );

    p1 = merge( p1, pHead2 );
}//////////////////////////////// END MERGE SORT ///////////
#endif
93
And now, similar to the above, but with a DLL ...


Code: [Select]
// insertSortedEraseDLL.h //  // 2017-02-11 //

// Note: still need to code copy ctor... and overloaded operator =
// But these are not needed in the short 'test code' used here. //

#ifndef _insertSortedEraseDLL_H_
#define _insertSortedEraseDLL_H_


template< typename T >
struct List
{
   struct Node
    {
        T val;
        Node* prev;
        Node* next;

        Node( const T& val = T() ) : val(val), prev(0), next(0) {}
    } ;

    Node* head;
    Node* tail;
    size_t len;
   

    List() : head(0), tail(0), len(0) {}
   
    ~List() { clear(); }
    void clear()
    {
        while( head )
        {
            Node* del = head;
            head = head->next;
            delete del;
        }
        tail = 0;
        len = 0;
    }

    void push_front( const T& val )
    {
        Node* nNode = new Node( val );
       
        if( len )
        {
            nNode->next = head; // N->A
            head->prev = nNode; // N<-A
            head = nNode;
        }
        else tail = head = nNode;
        ++len;
    }
    void push_back( const T& val )
    {
        Node* nNode = new Node( val );

        if( len )
        {
            tail->next = nNode; // B->N
            nNode->prev = tail; // B<-N
            tail = nNode;
        }
        else tail = head = nNode;
        ++len;
    }
   
    void insert_sorted( const T& val )
    {
        Node* nNode = new Node( val );
       
        // case 1 ... NOT inserted as the head node
        if( head  &&  head->val <= val )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur && cur->val <= val )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'
           
            prev->next = nNode;
            nNode->prev = prev;
           
            if( cur ) // NOT at tail
            {
                cur->prev = nNode;
                nNode->next = cur;
            }
            else // at tail
            {
                tail = nNode;
            }
        }
        else // insert at head ...
        {
            if( len )
            {
                nNode->next = head;
                head->prev = nNode;
                head = nNode;
            }
            else tail = head = nNode;
        }
       
        ++ len;
    }
   
    void insert_sorted( Node* nNode ) // nNode is a local copy //
    {
        nNode->next = nNode->prev = 0;
       
        // case 1 ... NOT inserted as the head node
        if( head  &&  head->val <= nNode->val )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur && cur->val <= nNode->val )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;
            nNode->prev = prev;

            if( cur ) // NOT at tail
            {
                cur->prev = nNode;
                nNode->next = cur;
            }
            else // at tail
            {
                tail = nNode;
            }
        }
        else // insert at head ...
        {
            if( len )
            {
                nNode->next = head;
                head->prev = nNode;
                head = nNode;
            }
            else tail = head = nNode;
        }

        ++ len;
    }
   
    // calls above method insert_sorted( Node* nNode ) //
    void insert_sort()
    {
        if( len > 1 ) // then head and cur != 0 //
        {
            Node* cur = head; // get copy //
            Node* next = cur->next; // get copy //
            head = tail = 0;
            len = 0;
            for( ; ; )
            {
                insert_sorted( cur );
                cur = next; // UPDATE from COPY //
                if( !cur ) break;
                next = cur->next;
            }
        }
    }
   
    // *** ASSUMPTION here *IS* that p passed in *IS* a *VALID* Node *** //
    void erase( Node* p )
    {
        if( p->prev && p->next )
        {
            p->prev->next = p->next;
            p->next->prev = p->prev;
        }
        else if( p->prev )
        {
            p->prev->next = 0;
            tail = p->prev;
        }
        else if( p->next )
        {
            p->next->prev = 0;
            head = p->next;
        }
        delete p;
        --len;
        if( !len ) head = tail = 0;
    }
   
    size_t size() const { return len; }
} ;


#endif


And a little test program for the above DLL ...

Code: [Select]
// insertSortedEraseDLL.cpp //  // 2017-02-11 //
 
 
#include <iostream>
#include <string>

// Note: still need to code copy ctor... and overloaded operator =
// But these are not needed in the short 'test code' used here. //
#include "insertSortedEraseDLL.h"

template< typename T >
void print(  const List< T >& lst, std::ostream& os = std::cout )
{
    typename List< T >::Node* cur;
    cur = lst.head;
    while( cur )
    {
        os << cur->val << ' ';
        cur = cur->next;
    }
    os << "size() = " << lst.size();
}

template< typename T >
void print_reversed(  const List< T >& lst, std::ostream& os = std::cout )
{
    typename List< T >::Node* cur;
    cur = lst.tail;
    while( cur )
    {
        os << cur->val << ' ';
        cur = cur->prev;
    }
    os << "size() = " << lst.size();
}



typedef List< std::string >::Node* MyNode;

MyNode find( List< std::string >& lst, const std::string& val )
{
    MyNode cur = lst.head;
    while( cur )
    {
        if( cur->val == val ) return cur;
        cur = cur->next;
    }
    return 0; // NOT found
}




int main()
{
    using namespace std;
   
    List< string > my_lst;

    cout << "Now testing push_front: ";
    my_lst.push_front( "Sam" );
    my_lst.push_front( "Joe" );
    my_lst.push_front( "Anne" );
    print( my_lst );
   
    cout << "\nPrinting reversed: ";
    print_reversed( my_lst );
    my_lst.clear();
   
   
    cout << "\n\nNow testing push_back: ";
    my_lst.push_back( "Sam" );
    my_lst.push_back( "Joe" );
    my_lst.push_back( "Anne" );
    print( my_lst );
   
    my_lst.insert_sort();
    my_lst.push_back( "Ann" );
    my_lst.push_front( "Zoe" );
    my_lst.insert_sort();
    cout << "\nAfter calling my_lst.insert_sort(): ";
    print( my_lst );

    cout << "\nPrinting reversed: ";
    print_reversed( my_lst );
    my_lst.clear();
   
    cout << "\n\nNow testing insert_sorted: ";
    my_lst.insert_sorted( "Anne" );
    my_lst.insert_sorted( "Sam" );
    my_lst.insert_sorted( "Zoe" );
    my_lst.insert_sorted( "Ann" );
    my_lst.insert_sorted( "Joe" );
    print( my_lst );

    cout << "\nPrinting reversed: ";
    print_reversed( my_lst );
   
    cout << "\n\nFind Ann ... ";
    MyNode cur = find( my_lst, "Ann" );
    if( cur )
    {
        cout << "Found ... erasing Ann ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Ann ...\n";
    cout << "Printing reversed: ";
    print_reversed( my_lst );
   
   
    cout << "\n\nFind Joe ... ";
    cur = find( my_lst, "Joe" );
    if( cur )
    {
        cout << "Found ... erasing Joe ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Joe ...\n";
    cout << "Printing reversed: ";
    print_reversed( my_lst );
   
   
    cout << "\n\nFind Sam ... ";
    cur = find( my_lst, "Sam" );
    if( cur )
    {
        cout << "Found ... erasing Sam ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Sam ...\n";
    cout << "Printing reversed: ";
    print_reversed( my_lst );
   
   
    cout << "\n\nFind Zoe ... ";
    cur = find( my_lst, "Zoe" );
    if( cur )
    {
        cout << "Found ... erasing Zoe ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Zoe ...\n";
    cout << "Printing reversed: ";
    print_reversed( my_lst );
   
   
    cout << "\n\nFind Anne ... ";
    cur = find( my_lst, "Anne" );
    if( cur )
    {
        cout << "Found ... erasing Anne ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Anne ...\n";
    cout << "Printing reversed: ";
    print_reversed( my_lst );

    cout << "\nPress 'Enter' to continue/exit ..." << flush;
    cin.get();
}
94
Below, we edit up to add a tail and len data member ... also an erase method ...

and we will also, firstly, separate out into its own file, (with guards), the code for a SLL ...

Note, we have NOT added iterators yet, so we are keeping all with public access ...
thus the nested Node class/struct has public access to enable free access to nodes in the SLL ...

Code: [Select]
// insertSortedEraseSLL.h //  // 2017-02-11 //

// Note: still need to code copy ctor... and overloaded operator =
// But these are not needed in the short 'test code' used here. //


#ifndef _insertSortedEraseSLL_H_
#define _insertSortedEraseSLL_H_


template< typename T >
struct List
{
   struct Node
    {
        T val;
        Node* next;

        Node( const T& val = T(), Node* next = 0 ) : val(val), next(next) {}
    } ;

    Node* head;
    Node* tail;
    size_t len;
   

    List() : head(0), tail(0), len(0) {}
   
    ~List() { clear(); }
    void clear()
    {
        while( head )
        {
            Node* del = head;
            head = head->next;
            delete del;
        }
        tail = 0;
        len = 0;
    }

    void push_front( const T& val )
    {
        head = new Node( val, head );
        ++len;
    }
    void push_back( const T& val )
    {
        Node* nNode = new Node( val );
        if( len )
        {
            tail->next = nNode; // B->N
            tail = nNode;
        }
        else tail = head = nNode;
        ++len;
    }
   
    // insert sorted by <= def'n of objects ...
    void insert_sorted( const T& val )
    {
        Node* nNode = new Node( val ); // recall next set to 0 //

        // case 1 : NOT inserted as the head node
        if( head != 0  &&  head->val <= val )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur != 0 && cur->val <= val )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;

            //if( cur ) // NOT at end
            nNode->next = cur; // link next to 'next' //
            if( !cur ) tail = nNode;
        }
        else // case 2 : insert at head ...
        {
            nNode->next = head;
            head = nNode; // update head //
            if( !len ) tail = head;
        }
       
        ++ len;
    }
   
    // used by method insert_sort() that follows ...
    void insert_sorted( Node* nNode )
    {
        // case 1 : NOT inserted as the head node
        if( head != 0  &&  head->val <= nNode->val )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur != 0 && cur->val <= nNode->val )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;

            // if( cur ) // NOT at end
            nNode->next = cur; // link next to 'next' //
            if( !cur ) tail = nNode;
        }
        else // case 2 : insert at head ...
        {
            nNode->next = head;
            head = nNode; // update head //
            if( !len ) tail = head;
        }
       
        ++ len;
    }

    // calls above method insert_sorted( Node* nNode ) //
    void insert_sort()
    {
        if( len > 1 ) // then head and cur != 0 //
        {
            Node* cur = head; // get copy //
            Node* next = cur->next; // get copy //
            head = tail = 0;
            len = 0;
            for( ; ; )
            {
                insert_sorted( cur );
                cur = next; // UPDATE from COPY //
                if( !cur ) break;
                next = cur->next;
            }
        }
    }
   
    bool erase( Node* ptr )
    {
        Node* prev = 0;
        Node* cur = head;
        for( ; cur && cur != ptr; cur = cur->next )
        {
            prev = cur;
        }
        // check end conditions //
        if( cur ) // found //
        {
            if( prev )
                prev->next = cur->next;
            else
                head = head->next;

            if( cur == tail ) tail = prev;

            delete cur;
            -- len;
            return true;
        }
        // NOT found //
        return false;
    }
   
    size_t size() const { return len; }
} ;

#endif


And now a short test program for the above ...

Code: [Select]
// insertSortedEraseSLL.cpp //  // 2017-02-13 //

#include <iostream>
#include <string>

// Note: still need to code copy ctor... and overloaded operator =
// But these are not needed in the short 'test code' used here. //
#include "insertSortedEraseSLL.h"


template< typename T >
void print(  const List< T >& lst, std::ostream& os = std::cout )
{
    typename List< T >::Node* cur;
    cur = lst.head;
    while( cur )
    {
        os << cur->val << ' ';
        cur = cur->next;
    }
    os << "size() = " << lst.size();
}


typedef List< std::string >::Node* MyNode;

MyNode find( List< std::string >& lst, const std::string& val )
{
    MyNode cur = lst.head;
    while( cur )
    {
        if( cur->val == val ) return cur;
        cur = cur->next;
    }
    return 0; // NOT found
}




int main()
{
    using namespace std;
   
    List< string > my_lst;

    cout << "Now testing push_front: ";
    my_lst.push_front( "Billy" );
    my_lst.push_front( "Sam" );
    my_lst.push_front( "Joe" );
    my_lst.push_front( "Anne" );
    my_lst.push_front( "Jill" );
   
    print( my_lst );
   
    my_lst.insert_sort();
    cout << "\nAfter calling my_lst.insert_sort(): ";
    print( my_lst );
    my_lst.clear();
   
    cout << "\n\nNow testing push_back: ";
    my_lst.push_back( "Billy" );
    my_lst.push_back( "Sam" );
    my_lst.push_back( "Joe" );
    my_lst.push_back( "Anne" );
    my_lst.push_back( "Jill" );

    print( my_lst );
   
    my_lst.insert_sort();
    cout << "\nAfter calling my_lst.insert_sort(): ";
    print( my_lst );
    my_lst.clear();
   

    cout << "\n\nNow testing insert_sorted: ";
   
    my_lst.insert_sorted( "Sam" );
    my_lst.insert_sorted( "Joe" );
    my_lst.insert_sorted( "Anne" );
   
    my_lst.push_back( "Billy" );
    my_lst.push_front( "Jill" );
   
    my_lst.insert_sort();
    print( my_lst );

    cout << "\n\nFind Billy ... ";
    MyNode cur = find( my_lst, "Billy" );
    if( cur )
    {
        cout << "Found ... erasing Billy ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Billy ...\n";

    print( my_lst );
   
   
    cout << "\n\nFind Anne ... ";
    cur = find( my_lst, "Anne" );
    if( cur )
    {
        cout << "Found ... erasing Anne ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Anne ...\n";
    print( my_lst );
   
   
    cout << "\n\nFind Sam ... ";
    cur = find( my_lst, "Sam" );
    if( cur )
    {
        cout << "Found ... erasing Sam ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Sam ...\n";
    print( my_lst );
   
   
    cout << "\n\nFind Jill ... ";
    cur = find( my_lst, "Jill" );
    if( cur )
    {
        cout << "Found ... erasing Jill ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Jill ...\n";
    print( my_lst );
   
   
    cout << "\n\nFind Joe ... ";
    cur = find( my_lst, "Joe" );
    if( cur )
    {
        cout << "Found ... erasing Joe ...\n";
        my_lst.erase( cur );
    }
    else cout << "NOT Found ... NOT erasing Joe ...\n";
    print( my_lst );

    cout << "\nPress 'Enter' to continue/exit ..." << flush;
    cin.get();
}
95
For students wanting to learn about several commonly used data container structures, and data handling algorithms, such as a linear search of the container to see if an element is there or not, and other methods such as erase, sort, etc...

the following pages may be, for you,

JUST what the Dr. has ordered

to help get you beyond the long start-up learning curve, for the linked-list type data structure, both single-linked and double-linked ...

Please see the following demo code progressions, beginning with a quite bare SLL ... and progressing to a fairly full featured DLL.




You may also like to see 6 Fast Steps to a C++ template class List ...
http://developers-heaven.net/forum/index.php/topic,2606.0.html


What follows, is a bare-bones list with an insert sorted method ...

Code: [Select]
// bareBonesListInsetSorted.cpp //  // 2017-02-11 //

#include <iostream>
#include <string>

using std::ostream;
using std::string;


template < typename T >
struct Node
{
    T data;
    Node* next;
   
    // ctors...
    Node( const T& data= T(), Node* next = 0 ) : data(data), next(next) {}

    // def'n for overloaded << for Node< T > objects ,,,
    friend ostream& operator << ( ostream& os, const Node* nd )
    {
        return os << nd->data;
    }
} ;


template< typename T >
struct List
{
    Node< T >* head;
   
    // default ctor...
    List() : head(0) {}
    // dtor...
    ~List() { clear(); }
   
    void clear()
    {
        Node< T >* del;
        while( head )
        {
            del = head;
            head = head->next;
            delete del;
        }
        // Note that head is set to 0 when done //
    }
   
    /*
    void push_front( const T& data )
    {
        // Note that this also sets the next to 'head' //
        Node< T >* newNode = new Node< T >( data, head );
        head = newNode; // update the head pointer //
    }
    */
   
    // insert sorted by <= def'n of objects ...
    void insert( const T& data )
    {
        Node< T >* nNode = new Node< T > (data); // recall next set to 0 //
       
        // case 1 : NOT inserted as the head node
        if( head != 0  &&  head->data <= data )
        {
            // find Node to insert after
            Node< T >* prev = head;
            Node< T >* cur = head->next;
            while( cur != 0 && cur->data <= data )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;

            //if( cur ) // NOT at end
            nNode->next = cur; // link next to 'next' //
        }
        else // case 2 : insert at head ...
        {
            nNode->next = head;
            head = nNode; // update head //
        }
    }
   
   
    // def'n of overloaded << for List objects ...
    friend ostream& operator << ( ostream& os, const List< T >& lst )
    {
        for( Node< T >* cur = lst.head; cur != 0; cur = cur->next )
        {
            os << cur << '\n'; //uses overloaded << for Node above //
        }
        return os;
    }
} ;


struct Student
{
    string name;
    int id;
   
    // ctors...
    Student( string name = "", int id = 0 ) : name(name), id(id) {}
   
    // for insert sorted method ...
    bool operator <= ( const Student& st ) const
    {
        return id <= st.id;
    }
   
    friend ostream& operator << ( ostream& os, const Student& st )
    {
        return os << st.name << ' ' << st.id;
    }
} ;






int main()
{
    using std::cout;
    using std::cin;
   
    List< Student > studs;
   
    studs.insert( Student("Sam", 3) );
    studs.insert( Student("James", 1) );
    studs.insert( Student("Annie", 4) );
    studs.insert( Student("Jill", 2) );
   
   
    cout << "studs now are: \n" << studs;
   
   
    cout << "\nPress 'Enter' to continue/exit ... ";
    cin.get();
}


Same as above ... but class version ...

Code: [Select]
// bareBonesListInsetSorted_classVersion.cpp //  // 2017-02-11 //

#include <iostream>
#include <string>

using std::ostream;
using std::string;

template < typename T > class List; // forward declaration //

template < typename T >
class Node
{
public:
    // ctors...
    Node( const T& data= T(), Node* next = 0 ) : data(data), next(next) {}

private:
    T data;
    Node* next;
   
    // def'n for overloaded << for Node< T > objects ,,,
    friend ostream& operator << ( ostream& os, const Node* nd )
    {
        return os << nd->data;
    }
    friend class List < T >;
} ;



template< typename T >
class List
{
public:
    // default ctor...
    List() : head(0) {}
    // dtor...
    ~List() { clear(); }
   
    void clear()
    {
        while( head )
        {
            Node< T >* del = head;
            head = head->next;
            delete del;
        }
        // Note that head is set to 0 when done //
    }
   
    void push_front( const T& data )
    {
        // Note that this alos sets the next to 'head' //
        Node< T >* newNode = new Node< T >( data, head );
        head = newNode; // update the head pointer //
    }
   
    // insert sorted by <= def'n of objects ...
    void insert( const T& data )
    {
        Node< T >* nNode = new Node< T > (data); // recall next set to 0 //
       
        // case 1 : NOT inserted as the head node
        if( head != 0  &&  head->data <= nNode->data )
        {
            // find Node to insert after
            Node< T >* prev = head;
            Node< T >* cur = head->next;
            while( cur != 0 && cur->data <= nNode->data )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;

            //if( cur ) // NOT at end
            nNode->next = cur; // link next to 'next' //
        }
        else // case 2 : insert at head ...
        {
            nNode->next = head;
            head = nNode; // update head //
        }
    }
    void print( ostream& os ) const
    {
        Node< T >* cur = head;
        for( ; cur != 0 ; cur = cur->next )
            os << cur << '\n'; //uses overloaded << for Node above //
    }
   
private:
    Node< T >* head;
   
} ;

// def'n of overloaded << for List objects ...
template < typename T >
ostream& operator << ( ostream& os, const List< T >& lst )
{
    lst.print( os );
    return os;
}



class Student
{
public:
    // ctors...
    Student( string name="", int id=0 ) : name(name), id(id) {}
   
    // for insert sorted method ...
    bool operator <= ( const Student& st ) const
    {
        return id <= st.id;
    }
   
private:
    string name;
    int id;
   
    friend ostream& operator << ( ostream& os, const Student& st )
    {
        return os << st.name << ' ' << st.id;
    }
} ;






int main()
{
    using std::cout;
    using std::cin;
   
    List< Student > studs;
   
    studs.insert( Student("Sam", 3) );
    studs.insert( Student("James", 1) );
    studs.insert( Student("Annie", 4) );
    studs.insert( Student("Jill", 2) );
   
   
    cout << "studs now are: \n" << studs;
   
   
    cout << "\nPress 'Enter' to continue/exit ... ";
    cin.get();
}


Same as above ... but with a nested Node class/struct ...

Code: [Select]
// bareBonesListInsetSorted_classVersion_nestedNode.cpp //  // 2017-02-11 //

#include <iostream>
#include <string>

using std::ostream;
using std::string;



template< typename T >
class List
{
public:
    // default ctor...
    List() : head(0) {}
    // dtor...
    ~List() { clear(); }
   
    void clear()
    {
        while( head )
        {
            Node* del = head;
            head = head->next;
            delete del;
        }
        // Note that head is set to 0 when done //
    }
   
    void push_front( const T& data )
    {
        // Note that this alos sets the next to 'head' //
        Node* newNode = new Node( data, head );
        head = newNode; // update the head pointer //
    }
   
    // insert sorted by <= def'n of objects ...
    void insert( const T& data )
    {
        Node* nNode = new Node( data ); // recall next set to 0 //
       
        // case 1 : NOT inserted as the head node
        if( head != 0  &&  head->data <= nNode->data )
        {
            // find Node to insert after
            Node* prev = head;
            Node* cur = head->next;
            while( cur != 0 && cur->data <= nNode->data )
            {
                prev = cur;
                cur = cur->next;
            }
            // ok found spot ... insert after 'prev'

            prev->next = nNode;

            //if( cur ) // NOT at end
            nNode->next = cur; // link next to 'next' //
        }
        else // case 2 : insert at head ...
        {
            nNode->next = head;
            head = nNode; // update head //
        }
    }
    void print( ostream& os ) const
    {
        Node* cur = head;
        for( ; cur != 0 ; cur = cur->next )
            os << cur->data << '\n';
    }
   
private:
    struct Node
    {
        Node( const T& data= T(), Node* next = 0 ) : data(data), next(next) {}

        T data;
        Node* next;
    } ;
   
    Node* head;
} ;

// def'n of overloaded << for List objects ...
template < typename T >
ostream& operator << ( ostream& os, const List< T >& lst )
{
    lst.print( os );
    return os;
}



class Student
{
public:
    // ctors...
    Student( string name="", int id=0 ) : name(name), id(id) {}
   
    // for insert sorted method ...
    bool operator <= ( const Student& st ) const
    {
        return id <= st.id;
    }
   
private:
    string name;
    int id;
   
    friend ostream& operator << ( ostream& os, const Student& st )
    {
        return os << st.name << ' ' << st.id;
    }
} ;






int main()
{
    using std::cout;
    using std::cin;
   
    List< Student > studs;
   
    studs.insert( Student("Sam", 3) );
    studs.insert( Student("James", 1) );
    studs.insert( Student("Annie", 4) );
    studs.insert( Student("Jill", 2) );
   
   
    cout << "studs now are: \n" << studs;
   
   
    cout << "\nPress 'Enter' to continue/exit ... ";
    cin.get();
}
96
Ask the Author / Re: FAKE NEWS
« Last post by David on January 27, 2017, 11:50:59 AM »
You may also like to see these pages:

Please note that you may need to copy the links below ...

and then to paste them into your browser 'goto' window to access the pages at the following links!!!


Talk about a long computer programming code ...
(50 kg lady's DNA stretches 66.6 return trips to Sun from Earth)

http://developers-heaven.net/forum/index.php/topic,2587.msg2985.html#msg2985


Is it possible to demonstrate the existence of a Creator?
If we can show that certain things really NEVER do happen by chance, then we can infer that they MUST have been created.  (This is similar to the well-known proof by contradiction in mathematics.)

http://developers-heaven.net/forum/index.php/topic,2587.msg3102.html#msg3102


Just to get a feel for the immensity of the barrier to random chance events, ever giving rise to life, consider the case of forming just one particular small protein, of 150 amino acid length, by undirected energy ...

http://developers-heaven.net/forum/index.php/topic,2587.msg3103.html#msg3103

Free Beginning Bible Study/Getting to know the Heavenly Author

http://developers-heaven.net/forum/index.php/topic,2587.0.html
97
Ask the Author / Re: FAKE NEWS
« Last post by David on January 27, 2017, 10:46:40 AM »
Another REALLY BIG often repeated FAKE NEWS (a myth) to BURST ...


"Myth 1: Your disease is caused by a chemical imbalance in the brain."
(see below: Dr. David Healy, Psychiatrist. Psychopharmacologist. Scientist. Author)

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4172306/

https://blogs.scientificamerican.com/cross-check/are-antidepressants-just-placebos-with-side-effects/

http://articles.mercola.com/sites/articles/archive/2010/03/09/antidepressants-are-no-better-than-placebo.aspx

http://www.naturalnews.com/047784_psychiatric_drugs_mental_health_withdrawals.html


Dr. David Healy
Psychiatrist. Psychopharmacologist. Scientist. Author.

https://davidhealy.org/psychiatry-gone-astray/

Myth 1: Your disease is caused by a chemical imbalance in the brain

Myth 2: It’s no problem to stop treatment with antidepressants

Myth 3: Psychotropic drugs for mental illness are like insulin for diabetes
(My comment: actually for type II diabetes, giving insulin just further decreases insulin sensitivity and the patient is then on a downward spiral - see info and data at 'the Peoples Chemist')

Myth 4: Psychotropic drugs reduce the number of chronically ill patients

Myth 5: Happy pills do not cause suicide in children and adolescents

Myth 6: Happy pills have no side effects

Myth 7: Happy pills are not addictive

Myth 8: The prevalence of depression has increased a lot

Myth 9: The main problem is not overtreatment, but undertreatment

Myth 10: Antipsychotics prevent brain damage


His conclusions:
How should we use psychotropic drugs?

I am not against using drugs, provided we know what we are doing and only use them in situations where they do more good than harm. Psychiatric drugs can be useful sometimes for some patients, especially in short-term treatment, in acute situations. But my studies in this area lead me to a very uncomfortable conclusion:

Our citizens would be far better off if we removed all the psychotropic drugs from the market, as doctors are unable to handle them. It is inescapable that their availability creates more harm than good. Psychiatrists, should, therefore, do everything they can to treat as little as possible, in as short time as possible, or not at all, with psychotropic drugs.



My comment:

But ...
if these drugs are all toxic ...
and have been shown to be NO more effective than a placebo ...
should we NOT, therefore, avoid their use completely?


P.S.

The video, at the next link below, seems fairly consistent with what the Bible teaches us about the devil and all his evil spirits ...

Note!  It documents that ...
evil spirits are real and that they all display the same singular personality, with the same ultimate goal - your destruction.

We are not to be led by them, but rather, we are to be led by the very loving, longsuffering, gentle and kind Holy Spirit of God.

We are thusly to live abundantly, joyfully, even now, overcoming all evil that God may permit to come our way, by doing the good things the Living God has already prepared in advance for us to do ... always trusting in His faithful grace to all who will trust in His provided Salvation, Jesus Christ, the Lord, who is soon to return as King of kings.

http://beforeitsnews.com/alternative/2016/07/doctor-claims-hallucinationsschizophrenia-may-be-demonic-entities-video-3381842.html

Above site no longer available as of 2019 so see copy/paste of an other site’s article below:

Three decades ago, had I seen a page labeled “Demons Are For Real”, I would have scoffed, “Oh Really!”

After working seven years in one of the largest psychiatric hospitals in the world, eighteen years in the psych department of a large state prison, two years in the largest mental health center in the city and over eleven years working in hospital ER’s dealing with psych crisis, I’ve seen things that fly in the face of both reason and my academic training.  After what I’ve experienced on the front lines, I have no doubt that demons exist.  I’ve both seen and spoken to them and they are very nasty.

The voices schizophrenics hear are not hallucinations as psychiatry maintains. Psychiatry insists that if you give these so called hallucinations any attention, such as questioning patients about their nature, you are making these patients worse.  Ignoring their demands to not query these patients, I found that the “voices” schizophrenics hear run well defined, predictable and destructive patterns very different from common hallucinations.

Once these “hallucinations” became aware that I was providing information to these patients that would weaken these voices, I became both a threat and a target.  It became clear that what psychiatry insisted were hallucinations were not only conscious but aware of what was going on around them.  In one case a patient I’d never seen before reported his voices warned him to stay away from me the minute I walked into the emergency room.

Providing people with knowledge of the existence of this menace and how they manifest in our lives is last thing these demonic entities desire.  They want you to go on believing that in this age of science, demons are fictional, a maniacal throwback to medieval and prehistoric days; tales of the uneducated.

They are thrilled that you ignore the twenty-three or more times Jesus mentioned casting out demons and even more pleased when you view the Bible as irrelevant to this issue.  They prefer you to believe that science is God and demons don’t exist.

It’s so much easier for these evil entities to go about their destructive work in stealth when their existence is denied by the millions upon whom they prey.  Like a tapeworm whose victim is ignorant of its presence, they don’t want you to know they exist.  This isn’t about religion.  This is about understanding that spirits exist and that evil spirits fear love and certain phrases from biblical text.

The information that upsets them most and to which they react the strongest is your becoming aware that they feed off of YOU.  They drain and steal your life energy.  In order to do this they must first turn your emotional state negative.  It is only negative emotional energy that sustains them.  Look at the state of the world today and their negative influence in the production of negative emotional energy becomes very clear.

They want no interference with their food source.  They don’t want you to have a family or friends or for you to be educated about how to interfere with their attacks.  They want you isolated and alone.  They hate when you go to Church or read the Bible and will attempt to convince you that these activities are boring and fruitless.  They do this in a manner least suspected, by inserting ideas in your head and then attempting to convince you to believe and act on them, often to your own detriment.  This is their way.

Being aware that demons really do exist is the first step toward countering and eliminating their negative influence on your life.

If you look back upon your life, you will see that when you get into a negative funk your energy disappears.  You can’t get anything done.  No one ever questions where their energy reserve has gone.  Many Schizophrenic patients reported they can actually feel their energy leave when they are attacked by their demonic voices.  Despite the one-to-one correlation between the appearance of the voices and their energy disappearing, they are not permitted awareness of this connection.

Who do they attack and why?

They attack anyone and everyone who unwittingly allows it.  They’ve been known to enter into people experimenting with Ouija boards, EVP, and playing around with satanic rituals and books.

Victims of severe physical, emotional or sexual abuse are prime targets.  They are already primed to feel bad about themselves.  Extreme cases of attacks are labeled paranoid schizophrenia by the psychiatric community, but every day common people like you and I are subject to attack too.

You need to know that being attacked does not mean you are crazy; it does not mean you are mentally ill.  There’s no malfunction of the brain.  Saying otherwise would be like saying that robbery or rape victims are mentally ill.  They were attacked – and so were you.

Why do they drain people’s energy?

The negative energy produced by negative emotion is their food source.  If they can get you to generate negative feelings, it is that negative emotion upon which they feast.  It may sound bizarre, but it is absolutely true.  It is the reason vampire movies subconsciously shake us to our core.  These entities are energy vampires.

How do they do this?

They get you to generate negative emotion for their consumption by inserting negative, guilt ridden, fearful or distressing thoughts into your mind then urging you to believe and respond to those thoughts as if they are true.  They are sly and use trickery, and lies to manipulate you into hearing, sensing, or feeling something troublesome or fearful.  (FEAR:  False Evidence Appearing Real)

Evidence of their activity becomes clear to the average person when an unwelcome intrusive thought barges into your mind, a thought so repulsive that on your own, you would never have come up with such ugliness and you certainly have no intention of acting on it.  You intuitively feel that such a thought is wrong, not yours and does not belong in your mind.  So think about this.  If it’s not your intention to bring up such a thought, entertain or act upon it, then from where did it originate?  If it’s not you and doesn’t belong in your head, then it has come from outside of you.

Are people helpless against this?

No. You are NOT helpless against these things, but you do need to get your head out of the sand, realize they exist and get to know how your enemy operates.  There are many things you can do to fight back and eventually reach a point where you can live your life without their interference and attacks.  If things are constantly going wrong in your life, there is a high probability you are under attack.  The most important thing they absolutely do not want you to know is that they can invade your mind and are energy parasites feeding off your life energy like a tapeworm absorbs food passing through your intestines.  These entities need negative emotional energy to survive.

God's Word ... His inspired Holy Book, the Bible ... is our Gold Standard.
98
Ask the Author / Re: FAKE NEWS
« Last post by David on January 24, 2017, 06:02:35 PM »
Is there a vaccine that is both effective and safe?

CDC Scientist Confirms Donald Trump Is Right About Vaccines and Autism
http://beforeitsnews.com/health/2016/11/cdc-scientist-confirms-donald-trump-is-right-about-vaccines-and-autism-2682230.html


Robert F Kennedy’s Devastating Quotes on Vaccines and the CDC Jan 26, 2017

http://beforeitsnews.com/alternative/2017/01/robert-f-kennedys-devastating-quotes-on-vaccines-and-the-cdc-jan-26-3469662.html

“The CDC is a very troubled agency, and it’s not just me saying that. There have been four separate, intensive federal investigations by the United States Congress—a three year investigation, 2001, 2002, 2003, by the United States Senate, Tom Coburn’s committee, by the Inspector General of HHS in 2008, by the Office Integrity in 2014. All of them have painted the CDC as a cesspool of corruption, of an agency that has become an absolute subsidiary of the pharmaceutical industry, and that has become a sock puppet, a spokesperson, a shill for the industry.”

“CDC is not an independent agency. It is a vaccine company. CDC owns over twenty vaccine patents. It sells about $4.6 billion of vaccines every year. And its primary metric for success in all the departments in the agency are vaccine sales. The groups, for example the Immunization Safety Office, where the scientists who are supposed to be looking at efficacy and safety in vaccines, they are no longer a public service…agency. They are subsumed in that metric: We have to sell as many of these things as possible. And so they do things to their science to make sure that nothing interferes—no information—interferes with sales.

“Now there are two divisions of the vaccine branch where we worry about the corruption. The first one is called the Advisory Committee on Immunization Practices. That is the committee that makes the decision about what new vaccines to add to the schvedule.”

“When I was a boy, I got three vaccines. My children got sixty-nine vaccines. It changed in 1989.”

“Why did it change in 1989?”

“Because in 1986, Congress, [was] drowning in pharmaceutical industry money—pharma puts more money into lobbying than any other industry—Pharmaceutical companies have more lobbyists on Capitol Hill than there are Congress people.”

“Do you think oil and gas has big influence in the Capitol? Well, that’s the next biggest. The pharmaceutical industry puts twice into lobbying, double the amount that the oil and gas, and four times what defense and aero space put in. So they control Congress.”

“In 1986, Congress passed the Vaccine Act, and there were good reasons for them to pass it. …At that time vaccine companies were being sued and were threatening to stop making vaccines. [Congress] said, okay, we’re going to insulate them from lawsuits. They made it illegal to sue a vaccine company in this country, no matter how reckless the behavior, no matter how negligent, no matter how toxic the product, no matter how grievous the injury to the child, you cannot sue.”

“You know how badly the pharmaceutical industry behaves when they are being sued, when there’s a whole bar of lawyers who spend their whole life looking for ways to sue the pharmaceutical industry and tell these stories to juries, and how many billions every year are won from that industry.”

“What do you think would happen if all of a sudden, all the lawyers disappeared, all the class action suits, all the multi district litigation, all the depositions, all the document searches, the discovery? Just gone. Nobody can sue. You can make anything you want.”

“And then they made it so that it was much easier to get a vaccine on the schedule than it was to get a pharmaceutical into the market. There’s no double blind placebo studies. They’re all fast tracked into the market place.”

“The decision is made by this group, the Advisory Committee on Immunization Practices. And you’d hope that the people who would serve on that committee would be kind of nerdy scientists who are narrowly focused on public health outcomes, but that’s not who they are. The people who serve on that committee, almost all of them, have strong financial ties to the pharmaceutical industry.”

“I’ll give you an example of how this committee works. In 1999, Paul Offit sat on that committee. And when you go to this committee, when you go to their meetings, the Advisory Committee on Immunization Practices is in one room, and then there’s a press deck in the next room. You have a whole bunch of seats there with guys who look like me, in suits. They’re Wall Street analysts, pharmaceutical analysts. They’re waiting to hear the decision. And as soon as they come out and announce which new vaccines they put on the schedule, those guys run out in the hallway and get on their cell phones, and you can watch the stocks spike. So it’s become an economic enterprise.”

“Paul Offit sat on the committee in 1999 that added the rota virus vaccine to the schedule. He owned a patent to a rota virus vaccine. He was then able to sell his vaccine to Merck for $186 million. He pocketed something around $29 million. He’s never allowed anybody to ask him exactly how much, but according to the formula that they use, he would have gotten at least $29 million.”

“That caused a little bit of a scandal in Washington, and the Inspector General of HHS was sent to investigate it. They did a complete investigation of the Advisory Committee on Immunization Practices, and what they found, what they concluded was what he did was not illegal under CDC rules. Sixty-four percent of the people who sat on that committee had conflicts that were similar to Paul Offit, and ninety-seven percent might have conflicts because the rest of them never made out their conflict of interest forms. And nobody ever made them do it.”

“It’s very difficult when those kinds of shenanigans are going on. The American people have faith that all of these new vaccines that were added, beginning in 1989, are put there solely because this committee is concerned with public health.”

Got it? This is four years’ worth of university political-science curriculum in seven minutes. Well, the actual title is politicized science.

Every American who can read should read it.

This is what is really going on at America’s number-one public health agency—the agency that is also a corporation.

This is war against the American people from within.


Autism and vaccines is a hot topic with a clear answer: Vaccines are dangerous and ineffective.
http://drrimatruthreports.com/category/03-vaccine-ebook/

Dr. Rima Replies: The Sky is Blue But Pro Vaccine Science is Anything But Settled!
http://drrimatruthreports.com/category/vaccination/page/2/



http://naturalsociety.com/vaccine-fraud-the-polio-elimination-by-vaccine-hoax/

http://www.naturalnews.com/035627_polio_vaccines_paralysis_India.html

http://www.greenmedinfo.com/blog/unsuccessful-modern-medical-miracles-fraud-behind-polio-and-smallpox-vaccines


https://thetruthaboutcancer.com/the-truth-about-vaccinations/


http://drrimatruthreports.com/vaccination-18th-century-pseudo-science/

http://www.naturalnews.com/035715_vaccines_history_fraud.html

http://drrimatruthreports.com/forced-vaccination-is-a-crime-against-humanity/


CDC Knowingly LIED About Mercury in Vaccines: Proof Has Surfaced
Posted on January 26, 2017
By Catherine J Frompovich

http://www.naturalblaze.com/2017/01/cdc-knowingly-lied-mercury-vaccines-proof.html

Finally, it’s coming to light and the fact is being told: Vaccines given to infants contained inordinate amounts of ethyl mercury in the form of Thimerosal; the CDC knew about it and conspired to keep the devastating reality of mercury damage from healthcare consumers and public health agencies.  A true crime against humanity and nothing short of federal agency child abuse!

Thanks to the intrepid vaccine safety advocacy work by Robert F. Kennedy Jr. and his writing partner Lyn Redwood, RN, MSN, we learn,
FDA’s Center for Biologics Evaluation and Research (CBER) was responsible for adding up the cumulative exposure to mercury from infant vaccines, a simple calculation that, astonishingly, had never been performed by either the FDA or the CDC. When the agency finally performed that basic calculation, the regulators realized that a six-month-old infant who received thimerosal-preserved vaccines following the recommended CDC vaccine schedule would have received a jaw-dropping 187.5 micrograms of mercury. [1]  [CJF emphasis added]

Those calculations were made back in the late 1990s and CDC officials have been covering up their voodoo vaccine consensus science ever since!  Those actions should be prosecuted as crimes against humanity, including excessive child abuse by a government agency, and the CDC should be revamped from the inside out; restructured; and ‘surgically’ separated from Big Pharma.

The CDC brainwashing of the global medical profession, international health agencies and the media regarding the deceitfulness of vaccine ‘safety’ is nothing short of criminal action, which must be addressed at every level: local school districts, state health agencies, national courts globally, and the World Health Organization, a ‘mouthpiece’ of CDC’s deceitfulness and fraudulent research and health recommendations.  None comes to mind more so than the CDC’s always trotting out the indicted Poul Thorsen’s infamous research that vaccines don’t cause autism!

What does mercury affect in the human body?  The brain and central nervous system! ... (see above link for graphs, charts, and the rest of the article.)
99
Ask the Author / Re: FAKE NEWS
« Last post by David on January 24, 2017, 05:07:54 PM »
You are about to go deep down into a dark rabbit hole ...

exposing a big reason why ALL (synthetic) drugs/(and all synthetic vitamins) are toxic.


Note that virtually almost all amino acids in God's creation are Left-Handed ...
(Note that of the 20 main amino acids that comprise all proteins in God's creation, only the simplest, Glycine is NOT racemic.)

And all our sugars are Right-Handed,

but NOTE,

****all synthetic**** chemistry yields a 50-50 racemic mix, i.e. an equal number of LEFT and RIGHT handed molecules,

and that some wrong handed molecules soon manifest their horrible devastation in a very visible manner,
(like the much cheaper racemic mix of Thalidomide did, with so many terrible birth defects.)

But ...
ALL wrong-handed molecules are really messing up the finely designed and highly interdependent complex chemistry, by competing/inhibiting with the correct handed molecules.

PLEASE be aware of this PROFOUND concept in BASIC CHEMISTRY ... but regrettably, ONE that is largely glossed over !!!
(I have yet to see it significantly addressed in any literature.)



Vitamin C: Is It Really Just Ascorbic Acid

1) Natural Whole Food Vitamins: Ascorbic Acid Is Not Vitamin C
http://www.saltmanonline.com/index.php?option=com_content&view=article&id=35:vitamin-c-is-it-really-just-ascorbic-acid&catid=14:health-tips&Itemid=111

2) Ascorbic acid is not vitamin C, Alpha tocopherol is not vitamin E, Retinoic acid is not vitamin A ...
And so on through the other vitamins
http://www.thedoctorwithin.com/vitaminC/Ascorbic-Acid-Is-Not-Vitamin-C/

3) Warning: Your Multi-Vitamin May Be Slowly Killing You! Does Your Multi-Vitamin Contain These Toxic 3 Ingredients?
https://thepeopleschemist.com/daily-dose/



Heads Up

Please note/recall that all complex Carbon based bio-molecules have many isomers including the left and right handed versions of 19+ amino acids ... with all the wrong handed versions being toxic.
(Virtually all Creation has only left-handed amino acids ... and this, obvious to a child, illustrates that SOMEONE did this,
i.e. it did NOT happen by a random chemical process as in all our synthetic chemistry ... and so this IS an ... all people will be held accountable proof of the Creator.)

Note that, as well, all creation has right-handed sugars, like dextrose (the right-handed version of 6 carbon cyclic hexose - glucose) whereas all our synthetic chemistry yields a racemic mix.

How dumbed-down and blinded and deceived ARE most, so as NOT to see,
that this obvious asymmetric chemistry did NOT happen by random chemical processes.

Note that ALL our synthetic chemistry always yields a racemic mix!!!

https://thepeopleschemist.com/fraud-in-medical-journals/


P.S.

Here is an experiment for you to try ...

ask a child in the age range of 4 to 14 ...

ask them about the results they will get for this thought experiment ...

If I were to take a bucket containing 1000 dimes, and then to toss all the contents of the pail up into the air, so that all the coins then fall down and are spread all over the floor of the room, and the child comes into that same room the next day, and sees that all the coins that had fallen onto the floor, are ALL HEADS UP ... what conclusion will that child draw?

When I did this with a young man about 12-13 years old, one recent morning in a McDonald's, in Pickering Ontario Canada, that child easily and immediately replied: SOMEONE had turned them all to be HEADS UP!

Thus, when we observe that all amino-acids (with but a few rare exceptions) in living things, are all LEFT-HANDED,
and that the sugars in living systems, for example, the Ribose in RNA and the Deoxyribose in DNA, are all RIGHT-HANDED, is it not OBVIOUS that this did NOT happen by random synthetic chemical processes that always produce a 50-50 combo of left and right handed products !!!

See also ...

Talk about a long computer programming code ...
(50 kg lady's DNA stretches 66.6 return trips to Sun from Earth)


http://developers-heaven.net/forum/index.php/topic,2587.msg2985.html#msg2985


Below, please see a copy paste of an email from the Peoples Chemist 2017/01/28

Unbeknownst to many Americans, four of the WORST vitamins are:

Vitamin D…calcium…resveratrol…and folic acid.


Avoid all of these!

Here's why…

1. Vitamin D pills

What so-called health experts say: "Your entire family is vitamin D deficient - even the family dog - and pills will correct it. The deficiency explains all your ill health...and even your bad haircut."

What science says: Vitamin D pills are hormones made by Big Pharma and disguised as "vitamins." The University of Colorado, recently showed how synthetic vitamin D was traditionally used as a "rodenticide" due to its "cumulative poisonous nature." Once mass production was developed by Hoffman La- Roche and BASF pharmaceuticals, it was turned into a "vitamin" courtesy of slick advertising and industry funded studies falsely touting its benefits (checkbook science).

Vitamin D pills can "plug up" the body, causing the synthetic vitamin to hide and tuck away into your fat layers (for up to 60 days!) where it disrupts "hormonal intelligence," causing excess calcification and dwindling health.

Gross! In contrast, naturally occurring vitamin D from cod liver oil or sun
exposure only lasts for up to 20 minutes, and quickly exerts its benefits before it's broken down and removed from the body.
(See my interview with the maker of the world’s best cod liver oil - rich in naturally occurring Vitamin D.)
(https://goo.gl/8iBZsT)

You don't need synthetic Vitamin D pills…Toss them.

2. Calcium

What "experts" say: "Choke down calcium pills or your bones will break."
Yea right!

What science says: Calcium pills can "freeze" your arteries by making them "calcified." You see, there's a HUGE difference between calcium from nature – which is organic calcium – and the poisonous calcium that's is in your multi-vitamin!

Fake calcium (in pill form) is so poisonous, that the Environmental Protection Agency (EPA) warns against having this crap in your water.

You don't need calcium pills…trash 'em!

3. Resveratrol

What "experts" say: "Resveratrol is the fountain of youth, except it comes in a pill, usually made by big Pharma, and is the next best thing since bacon. Honestly!"

What science says: Not a single human clinical trial substantiates longevity claims. In fact, some studies are showing resveratrol to be risky.

"Resveratrol, a polyphenol derived from red grapes, berries, and peanuts, has been shown to mediate death of a wide variety of cells. The mechanisms by which resveratrol mediates cell death include necrosis, apoptosis, autophagy, and others. While most studies suggest that resveratrol kills tumor cells selectively, evidence is emerging that certain normal cells such as endothelial cells, lymphocytes, and chondrocytes are vulnerable to resveratrol."

- Molecular Nutrition and Food Research, 2009

You don't need resveratrol…skip it!

4. Folic acid pills

What "experts" say: Choke down folic acid daily and forever escape fear, depression, heart disease, cancer or heck, high interest rates and predatory loans "as long as we get our 400 micrograms daily." (Cheesy smile here by huckster follows.)

What science says: Folic acid pills are yet another drug disguised as a vitamin. The Prostate, Lung, Colorectal, and Ovarian (PLCO) Cancer Screening trial has linked high folic acid intake with a 32% increased risk of breast cancer.

You don't need folic acid pills…chuck them in the garbage!

Bottom line…you've been told a bunch of lies by supplement hucksters and pretend "health gurus."

Chemists have discovered that many of these synthetic impostors - Vitamin D, calcium, folic acid, and resveratrol - can lead to calcium deposits, a common condition which, in severe cases, can narrow or block the arteries that feed the heart. This leads to heart failure.

If these imposters can lead to heart failure, then they're nothing more than poisons in disguise. Trash them!

Get a real, SAFE multivitamin at www.MySafeMulti.com

Dare to Live Young,
The People's Chemist

P.S. Remember to trash your Vitamin D, calcium, resveratrol, and folic acid pills! You don't need ANY of them to be healthy!…in fact, they can destroy health. Get the facts at www.MySafeMulti.com And for a truly safe source of daily nutrients, use Daily Dose - the only multivitamin product you need. Try your first bottle at www.MySafeMulti.com 

100
Ask the Author / Re: FAKE NEWS
« Last post by David on January 24, 2017, 04:41:44 PM »
Do you recall the news about two years ago, when Ebola was threatening to sweep through Africa and everywhere ...

recall that the news then ... the MSN THAT was repeated and repeated then was that:

There is presently no known effective treatment for Ebola.

But that was FAKE NEWS also!!!

Please see:

http://drrimatruthreports.com/silver-info-you-need/


Note also that it was Dr. Rima who first made me aware of the amazing broad spectrum healing effects of hemp oil, and especially her High Potency CBD Hemp Oil.

http://drrimatruthreports.com/aboutus/meet-rima-e-laibow-md/
Pages: 1 ... 8 9 [10]