the problem seems to be in the show_int_sllist().

main

#include "My_Int_Sllist.h"
#include <iostream>

using namespace std;

int main()
{
	//Test1
	my_int_sllist b;
	b.push_back(10);
	b.show_int_sllist();
	return 0;
}

INTERFACE NODE

//class used to create a node

class my_int_node
{
public:
	//member that stores the nodes data value
	int data;
	
	//pointer to next list node
	my_int_node* next;

	/*constructor that creates a node when invoked
	by specifiying what value and a pointer to the 
	next node */
	inline my_int_node(int value, my_int_node* follow=0)
	{
		data=value;
		next=follow;
	}
};

INTERFACE LIST

#include "My_Int_Node.h"

class my_int_sllist
{
public:
	//constructor to create an empty list
	my_int_sllist();

	/*constrcutor to create a list of a certain size
	and intialize it to a value*/
	my_int_sllist(size_t intial_size, size_t value);

	/*Insert a node containing number at the first position 
	of the singly linked list*/
	void push_front(int number);

	/*Insert a new node containing number at the last position 
	of the singly linked list*/
	void push_back(int number);

	// Delete the first node of the singly linked list
	void pop_front();

	// Delete the first node of the singly linked list
	void pop_back();

	//number of nodes that store values
	int size();

	//prints out the list
	void show_int_sllist();

private:
	//pointers to front and back of list
	my_int_node* head, *tail;

};

IMPLEMENTATION

#include "My_Int_Sllist.h"
#include <iostream>
using namespace std;

my_int_sllist::my_int_sllist()
{
	head=0;
	tail=0;
}

void my_int_sllist::push_front(int number)
{
	/*1.Creates an empty node
	2.nodes data member initalized to a particular value
	3.adding to front, so to connect current node to rest must update
	the next member to head position
	4.must update value of head to make it point to current node*/
	head=new my_int_node(number,head);

	//if their is an empty list
	if(tail==0)
	{
		tail=head;
	}
}

void my_int_sllist::push_back(int number)
{
	cout<<"enter's push_back";
	//the list isn't empty
	if(tail!=0)
	{
		/*1.create an empty node
		2.the new nodes member is initalized to number
		3.next is set to null since it is at end of list 
		and doesn't need to create a new link to the next node
		4.tail->next is the next member of the node pointed to by tail 
		thus making the next member point to the new node*/
		tail->next=new my_int_node(number);

		//must update value of tail so that the last value may be accessed
		tail=tail->next;
	}
	//list is empty
	else
	{
		/*1.create a empty node
		2.new nodes member is initalized to number
		3.need to update tail and head pointer so that 
		they point to the node allowing access*/
		head=tail=new my_int_node(number);
	}
}

void my_int_sllist::pop_front()
{
	//empty list
	if(head==0&&tail==0)
	{
		cout<<"can't remove from an already empty list\n";
	}

	//temp is a pointer that gets node pointed to by head
	my_int_node* temp=head;

	//one node in the list
	if(head==tail)
	{
		head=tail=0;
	}
	//list contains more than one node
	else
	{
		/*head updated to next node that follows by using the
		pointer next of the first node */
		head=head->next;
	}
	delete temp;
}

void my_int_sllist::pop_back()
{
	//one node in list
	if(head==tail)
	{
		delete head;
		head=tail=0;
	}
	//empty list
	else if(head==0&&tail==0)
	{
		cout<<"since the list is empty can't delete\n";
	}
	//more than one node in the list
	else
	{
		//find the node before tail
		my_int_node* temp;

		/*begin loop at head until the next pointer of the node that 
		temp points to doesn't equal to tail and increment so that 
		temp pointer will get updated by using the next pointer*/
		for(temp=head; temp->next!=tail; temp=temp->next)
		{
			//deletes the node that tail points to
			delete tail;

			//tail gets updated to temp which is last position in list
			tail=temp;
			
			//since last position in list must make pointer =0
			tail->next=0;
		}
	}
}		

void my_int_sllist::show_int_sllist()
{
	my_int_node* temp=head;
	while(temp->next!=tail)
	{
		cout<<temp->data<<"\n";
		temp=temp->next;
	}
}

sort of seems to be working, but won't print last value :(

void my_int_sllist::show_int_sllist()
{
	my_int_node* temp=head;
	while(temp->next!=0)
	{
		cout<<temp->data<<"\n";
		temp=temp->next;
	}
	/*for(temp=head; temp->next!=tail; temp=temp->next)
	{
		cout<<temp->data<<"\n";
	}*/
}

nvm figured it out.
Thanks.

Why doesn't pop_back method work? or is their something wrong with show_int_sllist()? Has to be pop_back because when i get rid of show_int_sllist error still shows up. PLEASE HELP.

#include "My_Int_Sllist.h"
#include <iostream>
using namespace std;

my_int_sllist::my_int_sllist()
{
	head=0;
	tail=0;
	siz=0;
}

void my_int_sllist::push_front(int number)
{
	/*1.Creates an empty node
	2.nodes data member initalized to a particular value
	3.adding to front, so to connect current node to rest must update
	the next member to head position
	4.must update value of head to make it point to current node*/
	head=new my_int_node(number,head);
	//if their is an empty list
	if(tail==0)
	{
		tail=head;
	}
	siz++;
}

void my_int_sllist::push_back(int number)
{
	//the list isn't empty
	if(tail!=0)
	{
		/*1.create an empty node
		2.the new nodes member is initalized to number
		3.next is set to null since it is at end of list 
		and doesn't need to create a new link to the next node
		4.tail->next is the next member of the node pointed to by tail 
		thus making the next member point to the new node*/
		tail->next=new my_int_node(number);

		//must update value of tail so that the last value may be accessed
		tail=tail->next;
	}
	//list is empty
	else
	{
		/*1.create a empty node
		2.new nodes member is initalized to number
		3.need to update tail and head pointer so that 
		they point to the node allowing access*/
		head=tail=new my_int_node(number);
	}
	siz++;
}

void my_int_sllist::pop_front()
{
	//int el=head->data;
	//temp is a pointer that gets node pointed to by head
	my_int_node* temp=head;

	//empty list
	if(head==0&&tail==0)
	{
		cout<<"can't remove from an already empty list\n";
	}

	//one node in the list
	else if(head==tail)
	{
		head=tail=0;
		siz--;
	}
	//list contains more than one node
	else
	{
		/*head updated to next node that follows by using the
		pointer next of the first node */
		head=head->next;
		siz--;
	}
	delete temp;
	temp=NULL;
		//cout<<"value deleted"<<el<<"\n";
}

void my_int_sllist::pop_back()
{
	cout<<"enter pop_back";
	//int el=tail->data;
	
	//empty list
	/*if(head==0&&tail==0)
	{
		cout<<"since the list is empty can't delete\n";
	}*/
	//one node in list
	if(head==tail)
	{
		cout<<"enter head==tail?";
		delete head;
		head=tail=0;
		siz--;
	}
	else
	{
		cout<<"enter's other condition";
		my_int_node* temp;
		for(temp=head; temp->next!=tail; temp=temp->next)
		{
			delete tail;
			tail=temp;
			tail->next=0;
		}
		siz--;
	}
}		

int my_int_sllist::size()
{
	return siz;
}
void my_int_sllist::show_int_sllist()
{
	my_int_node* temp=head;
	if(head==0&&tail==0)
	{
		cout<<"nothing to show\n";
	}
	else
	{
		while(temp->next!=0)
		{
			cout<<temp->data<<"\n";
			temp=temp->next;		
		}
		cout<<temp->data<<endl;
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.