/*
 * functions.cpp
 *
 *  Created on: May 15, 2010
 *      Author: abdulrahman
 */

#include <iostream>
using namespace std;

// structure for the link list
struct Node {
	char data;
	Node* next;
	Node(char d, Node* n);
};

Node::Node(char d, Node* n)
{
	data = d;
	next = n;
}

// the function that builds the link list
Node* build(char* p)
{
	if(p == 0)
		return NULL;
	else
		return new Node((*p), build(p+1));
}


//the function that prints the link list
void print(Node* p)
{
	cout<<'<';
	while(p != NULL)
	{
		cout<< p->data;
		p = p->next;
		if(p != NULL)
			cout<<'-';
	}
	cout<<'>';
}


// the function that deletes the link list
void dispose(Node* p)
{
	if(p == NULL)
	{
		delete p;
	}
	else
	{
		Node* temp=p;
		p = p->next;
		delete temp;
		dispose(p);
	}
}

// the function that does the insertion sort in an ascending order
void sort(Node* &p)
{
	if(p != NULL)
	{
		Node* temp = p;

		while(temp != NULL)
		{
			if(temp->data <= p->data)
			{
				char value = p->data;
				p->data = temp->data;
				temp->data = value;
				temp = temp->next;
				temp = temp->next;
			}
			else
				temp = temp->next;
		}
		sort(temp);
	}
}



// the main function
#include <iostream>
using namespace std;


int main(int argc, char* argv[])
{
	Node* p;
	p = build(argv[1]);

	print(p);

	return 0;
}
