Self-Sorting Linked List in C++

Graham's Code

* Self Sorting Linked List *
* Programmer: Graham Nedelka *
* Created in May, 2013 *
* Computer Science 116: Data Structures *

#include <iostream>
#include <time.h>
#include <fstream>
#include <iomanip>
#include <vector>

using namespace std;

struct node{
int data;
node *next;
node *previous;
node(int value){data = value; next = NULL; previous = NULL;};

class LL{
node *head;
node *tail;
LL() {head = NULL;tail = NULL;};
void add(int number);
void show();

void LL::add(int value){
node *current = new node(value);
if (head == NULL){
tail = current;
head = current;
node *temp = head;
node *temptail = tail;
if (value < temp->data){
node *temp2 = new node(value);
temp2->next = head;
head = temp2;
while(temp->next != NULL){
if (value > temp->data and value < temp->next->data){
current->next = temp->next;
temp->next = current;
temp = temp->next;
else if (current->data > temptail->data){

View original post 137 more words


About Khuram Ali

Programming... Programming and Programming...!!!

Posted on May 17, 2013, in C++, Data Structures. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: