Esempio n. 1
0
void List::Print() const {
	if(head==NULL)
		cout << "The list is empty." << endl << endl;
	else{
		cout << "The current list is as follows:" << endl << endl;
		ListNode * index = head;
		cout << index->getMyInt() << endl;
		while(index->getNext()!=NULL){
			index=index->getNext();
			cout << index->getMyInt() << endl;
		}
		cout << endl << endl;
	}
}
Esempio n. 2
0
void List::Insert(int newInt){
	if(head==NULL){
		ListNode * h = new ListNode(newInt,NULL);
		head=h;
	}
	else{
		ListNode * index = head;
		ListNode * prev = NULL;
		ListNode * newListNode = new ListNode(newInt);
		while(index->getNext()!=NULL && index->getMyInt()<=newInt){
			prev=index;
			index=index->getNext();
		}
		if(index->getMyInt()>newInt){
			newListNode->setNext(index);
			if(prev!=NULL)
				prev->setNext(newListNode);
			else
				head=newListNode;
		}
		else
			index->setNext(newListNode);
	}
}