acoxia 26 Newbie Poster

Ended up solving it don't know how delete post however

include <iostream>
using namespace std;
/*
 *  linkedlist.h
 *  linkedlist
*/ 
struct node {
	int data;
	node * next;
};

class linkedlist {
	node * hd;
	
	
public:
	linkedlist(){
		hd = NULL;
	}
	
	void add_to_end(int data) {
		
		//find end of list
		if (hd == NULL){
			node * new_node;
			new_node = new node;
			new_node->data = data;
			hd = new_node; 
		}
		else{
			node * temp;
			for (temp = hd; temp->next != NULL; temp = temp->next){}
			
			node * new_node;
			new_node = new node;
			new_node->data = data;
			
			temp->next = new_node; 
		}
	}
	
	void add_to_beginning(int data){
		// make new node
		node * new_hd;
		new_hd = new node;
		new_hd->data = data;
		// points to head
		new_hd->next = hd;
		// head equals new head
		hd = new_hd; 
	}
	
	void add_to_position(int data, int pos){
		int i; 
		node * temp;
		node * new_node;
		new_node = new node;
		new_node->data = data;
		
		if (pos==0){
			add_to_beginning(data);
		}
		else{
			for( temp = hd, i = 1;  temp->next != NULL && i <= pos; temp = temp->next, i++){} // find node
			
			if (temp->next != NULL){
				// add to list
				new_node->next = temp->next;
			}
			temp->next = new_node;
		}
		
	}
	void delete_at_position( int pos){
	int i; 
	
	// head 	
	if (pos == 0){
	node * temp;
	temp = hd;
	hd = hd->next;
	delete temp;		
	}		
	// end	
	
	else{
	int i;
	node * temp;	
	
	for( temp = hd, i = 2;  temp->next != NULL && i <= pos; temp = temp->next, i++){} // find node
	
	// if end
	if (temp->next == NULL){
	node * temp2;
	temp2 = temp->next;
	delete temp;
		
			}	
	// if in middle
else{

}



}
				
		
	}
	
	
	
	void print_list() {
		node * temp;
		for (temp = hd; temp != NULL; temp = temp->next){
			cout<< temp->data;
		}
	}
	
};
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.