<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>templates | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/templates/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Mon, 31 Jan 2011 10:52:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>C++ program to implement stack using Linked List</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:50:47 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[C Programs]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1252</guid>

					<description><![CDATA[<p>#include template class Node { friend LinkedStack; private: T data; Node *link; }; template class LinkedStack { public: LinkedStack() {top = 0;} ~LinkedStack(); int IsEmpty() const {return top == 0;} T Top() const; LinkedStack&#038; Add(const T&#038; x); LinkedStack&#038; Delete(T&#038; x); private: Node *top; }; template LinkedStack::~LinkedStack() {// Stack destructor.. Node *next; while (top) { next</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/">C++ program to implement stack using Linked List</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include <iostream.h>
template<class T>
class Node
{
	friend LinkedStack<T>;
	private:
	T data;
	Node<T> *link;
};
template<class T>
class LinkedStack {
	public:
		LinkedStack() {top = 0;}
		~LinkedStack();
		int IsEmpty() const {return top == 0;}
		T Top() const;
		LinkedStack<T>& Add(const T& x);
		LinkedStack<T>& Delete(T& x);
	private:
		Node<T> *top; 
};
	template<class T>
LinkedStack<T>::~LinkedStack()
{// Stack destructor..
	Node<T> *next;
	while (top) {
		next = top->link;
		delete top;
		top = next;
	}
}
template<class T>
T LinkedStack<T>::Top() const
{// Return top element.
	if (IsEmpty()) cout<<"Stack empty:";
	else
		return top->data;
}
	template<class T>
LinkedStack<T>& LinkedStack<T>::Add(const T& x)
{// Add x to stack.
	Node<T> *p = new Node<T>;
	p->data = x;
	p->link = top;
	top = p;
	return *this;
}
	template<class T>
LinkedStack<T>& LinkedStack<T>::Delete(T& x)
{// Delete top element and put it in x.
	if (IsEmpty()) 
	{
		cout<<"Stack empty";
		return *this;
	}
	x = top->data;
	Node<T> *p = top;
	top = top->link;
	delete p;
	return *this;
}
void main(void)
{
	int x;
	LinkedStack<int> S;
	S.Add(1).Add(2).Add(3).Add(4);
	cout << "Stack should be 1234" << endl;
	cout << "Stack top is " << S.Top() << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
	S.Delete(x);
	cout << "Deleted " << x << endl;
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/">C++ program to implement stack using Linked List</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-linked-list/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>C++ program to implement Stack using Formula Based Representation</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/#comments</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 03 Feb 2011 10:47:47 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[Formula Based Representation]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[Linked Lists]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[stack]]></category>
		<category><![CDATA[C Programs]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1250</guid>

					<description><![CDATA[<p>#include #include template class Stack { public: Stack(int MaxStackSize); ~Stack(){delete[] S;} int IsEmpty()const{return top==-1;} int IsFull()const{return top==MaxTop;} T Peek()const; void Push(T); T Pop(); void Display(); private: int top; //current top of stack int MaxTop; //max val for top T *S; //element array }; template Stack::Stack(int MaxStackSize) { //stack constructor MaxTop=MaxStackSize-1; S=new T[MaxStackSize]; top=-1; } template</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/">C++ program to implement Stack using Formula Based Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
template<class T>
class Stack
{
	public:
		Stack(int MaxStackSize);
		~Stack(){delete[] S;}
		int IsEmpty()const{return top==-1;}
		int IsFull()const{return top==MaxTop;}
		T Peek()const;
		void Push(T);
		T Pop();
		void Display();
	private:
		int top; //current top of stack
		int MaxTop; //max val for top
		T *S; //element array
};
	template<class T>
Stack<T>::Stack(int MaxStackSize)
{
	//stack constructor
	MaxTop=MaxStackSize-1;
	S=new T[MaxStackSize];
	top=-1;
}
template<class T>
T Stack<T>::Peek()const
{
	if(IsEmpty()) //top fails
		return 0;
	else
		return S[top];
}
	template<class T>
void Stack<T>::Push(T x)
{
	if(IsFull())
		cout<<"no memory()"; //add fails
	else
	{
		S[++top]=x;
	}
}
	template<class T>
T Stack<T>::Pop()
{
	T x;
	if(IsEmpty())
	{
		cout<<"stack is empty\n";
		return -1;
	}
	else
	{
		x=S[top--];
		return x;
	}
}
	template<class T>
void Stack<T>::Display()
{
	if(IsEmpty())
		cout<<"out of bounds"; //delete fails
	else
		for(int i=top;i>=0;i--)
		{
			cout<<S[i]<<"\t";
		}
}
void menu()
{
	cout<<"1.Push\n 2.Pop\n 3.Peek\n 4.Display\n";
}
void main()
{
	Stack<int>iobj(5);
	int ch,x;
	clrscr();
	do
	{
		menu();
		cout<<"enter the choice\n";
		cin>>ch;
		switch(ch)
		{
			case 1:
				cout<<"enter x value to push into the stack\n";
				cin>>x;
				iobj.Push(x);
				break;
			case 2:
				x=iobj.Pop();
				if(x!=-1)
					cout<<"poped value is \t"<<x<<endl;
				break;
			case 3:
				x=iobj.Peek();
				cout<<"top most value is \t"<<x<<endl;
				break;
			case 4:
				iobj.Display();
				break;
		}
	}while(ch>=1&&ch<=4);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/">C++ program to implement Stack using Formula Based Representation</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/c-program-to-implement-stack-using-formula-based-representation/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Program to represent Indirect Addressing of Linear List using Templates</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Sat, 29 Jan 2011 10:49:31 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[Indirect Addressing]]></category>
		<category><![CDATA[indirect list]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[linear list]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[linked list]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1218</guid>

					<description><![CDATA[<p>IndirectList(int MaxLinearSize=10);<br />
~IndirectList();//destructor<br />
int IsEmpty()const{return length==0;}<br />
int Length()const{return length;}<br />
int Find(int k,T&#038;x)const;<br />
int Search(const T&#038;x)const;<br />
void Delete(int k,T&#038;x);<br />
void Insert(int k,const T&#038;x);<br />
void Output()const;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/">Program to represent Indirect Addressing of Linear List using Templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
template<class T>
class IndirectList
{
	private:
		int length;
		int MaxSize;
		T**table; 
	public:
		IndirectList(int MaxLinearSize=10);  	
		~IndirectList();//destructor
		int IsEmpty()const{return length==0;}
		int Length()const{return length;}
		int Find(int k,T&x)const;
		int Search(const T&x)const;
		void Delete(int k,T&x);

		void Insert(int k,const T&x);

		void Output()const;
};
	template<class T>
IndirectList<T>::IndirectList(int MaxListSize)
{
	MaxSize=MaxListSize;
	table=new T*[MaxSize];
	length=0;
}
	template<class T>
IndirectList<T>::~IndirectList()
{
	for(int i=0;i<length;i++)
		delete table[i];
	delete[]table;
}
template<class T>
int IndirectList<T>::Find(int k,T&x)const
{
	if(k<1||k>length)
		return 0; //no kth element
	if(x==*table[k-1])
		return 1;
	else
		return 0;
}
template<class T>
int IndirectList<T>::Search(const T&x)const
{
	for(int i=0;i<length;i++)
		if(*table[i]==x)
			return ++i;
	return 0;
}
	template<class T>
void IndirectList<T>::Delete(int k,T&x)
{
	if(Find(k,x))
	{
		for(int i=k;i<length;i++)
			table[i-1]=table[i];
		length--;
	}
	else
		cout<<"out of bounds\n";
}
	template<class T>
void IndirectList<T>::Insert(int k,const T&x)
{
	if(k<0||k>length)
		cout<<"out of bounds\n";
	if(length==MaxSize)
		cout<<"no memory\n";
	for(int i=length-1;i>=k;i--)
		table[i+1]=table[i];
	table[k]=new T;
	*table[k]=x;
	length++;
}
template<class T>
void IndirectList<T>::Output()const
{
	if(IsEmpty())
		cout<<"list is empty\n";
	else
		for(int i=0;i<length;i++)
			cout<<*table[i]<<"\t";
}
void menu()
{
	cout<<"\n MENU\n";
	cout<<"1.Length\n";
	cout<<"2.Find\n";
	cout<<"3.Search\n";
	cout<<"4.Delete\n";
	cout<<"5.Insert\n";
	cout<<"6.Output\n";
}
void main()
{
	int choice;
	int k,x,len,p;
	clrscr();
	IndirectList<int>obj;
	do
	{
		menu();
		cout<<"enter choice\n";
		cin>>choice;
		switch(choice)
		{
			case 1:
				len=obj.Length();
				if(len==0)
					cout<<"List is empty\n";
				else
					cout<<"length of Indirectlist is "<<len<<endl;
				break;
			case 2:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				p=obj.Find(k,x);
				if(p==1)
					cout<<"found"<<endl;
				if(p==0)
					cout<<"not found"<<endl;
				break;
			case 3:
				cout<<"enter x(value)\n";
				cin>>x;
				p=obj.Search(x);
				if(p)
					cout<<"searching is sucessful and found at "<<p<<endl;
				else
					cout<<"searching not sucessful"<<endl;
				break;
			case 4:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				obj.Delete(k,x);
				break;
			case 5:
				cout<<"enter k,x(index and value)\n";
				cin>>k>>x;
				obj.Insert(k,x);
				break;
			case 6:
				cout<<"elements in the list are:\n\n";
				obj.Output();
				break;
			default:
				cout<<"invalid choice\n";
		}
	}
	while(choice>=1&&choice<=6);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/">Program to represent Indirect Addressing of Linear List using Templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-represent-indirect-addressing-of-linear-list-using-templates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program to implement linked representation of Linear list using templates</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Fri, 28 Jan 2011 10:47:11 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[linear list]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[linked list]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1214</guid>

					<description><![CDATA[<p>#include #include #include template class ChainNode { friend Chain; private: T data; ChainNode*link; }; template class Chain { private: ChainNode*first; public: Chain() { first=0; } ~Chain(); int IsEmpty()const; int Length()const; int Find(int k,T&#038;x); int Search(const T&#038;x); void Delete(int k,T&#038;x); void Insert(int k,const T&#038;x); void Output(); }; template Chain::~Chain() { ChainNode*next; while(first) { next=first->link; delete first;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/">Program to implement linked representation of Linear list using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
#include<stdlib.h>
template<class T>
class ChainNode
{
	friend Chain<T>;
	private:
	T data;
	ChainNode<T>*link;
};
template<class T>
class Chain
{
	private:
		ChainNode<T>*first; 
	public:
		Chain()
		{
			first=0;
		}
		~Chain();
		int IsEmpty()const;
		int Length()const;
		int Find(int k,T&x);
		int Search(const T&x);
		void Delete(int k,T&x);
		void Insert(int k,const T&x);
		void Output();
};
	template<class T>
Chain<T>::~Chain()
{
	ChainNode<T>*next;
	while(first)
	{
		next=first->link;
		delete first;
		first=next;
	}
}
template<class T>
int Chain<T>::Length()const
{
	ChainNode<T>*current=first;
	int len=0;
	while(current)
	{
		current=current->link;
		len++;
	}
	return len;
}
	template<class T>
int Chain<T>::Find(int k,T&x)
	//set x to the kth element in the chain
	//return 0 if no kth element, return 1 otherwise
{
	if(k<1)
		return 0;
	ChainNode<T>*current=first;
	int index=1; //index of current
	while(index<k&#038;&#038;current)
	{
		current=current->link;
		index++;
	}
	if(current&&x==current->data)
		return 1;
	else
		return 0; //no kth element
}
	template<class T>
int Chain<T>::Search(const T&x)
{
	ChainNode<T>*current=first;
	int index=1; //index of current
	while(current&&current->data!=x)
	{
		current=current->link;
		index++;
	}
	if(current)
	{
		return index;
	}
	else
		return 0;
}
	template<class T>
void Chain<T>::Delete(int k,T&x)
{
	if(k<1||!first)
		cout<<"out of bounds\n"; //no kth element
	ChainNode<T>*p=first;
	if(k==1) //p is already at k
		first=first->link; //remove
	else
	{
		ChainNode<T>*q=first;
		for(int index=1;index<k-1&#038;&q;index++)
		{
			q=q->link;
		}
		if(!q||!q->link)
			cout<<"the element doesnot exist\n";
		p=q->link;
		q->link=p->link; //remove from linked list
		//free node p
		delete p;
	}

}
	template<class T>
void Chain<T>::Insert(int k,const T&x)
{
	if(k<0)
		cout<<"out of bounds\n"; //no kth element
	//p will be eventually to kth node
	ChainNode<T>*p=first;
	for(int index=1;index<k&#038;&p;index++)
		p=p->link;
	if(k>0&&!p)
		cout<<"out of bounds\n"; //no kth element
	ChainNode<T>*y=new ChainNode<T>;
	y->data=x;
	if(k)
	{
		//insert after p
		y->link=p->link;
		p->link=y;
	}
	else
	{
		y->link=first;
		first=y;
	}
}
	template<class T>
void Chain<T>::Output()
{
	ChainNode<T>*p=first;
	while(p)
	{
		cout<<p->data<<"\t";
		p=p->link;
	}
}


void menu()
{
	cout<<"\n MENU\n";
	cout<<"1.Length\n";
	cout<<"2.Find\n";
	cout<<"3.Search\n";
	cout<<"4.Delete\n";
	cout<<"5.Insert\n";
	cout<<"6.Output\n";
}
void main()
{
	int choice;
	int k,x,len,p;
	clrscr();
	Chain<int>obj;
	do
	{
		menu();
		cout<<"enter choice\n";
		cin>>choice;
		switch(choice)
		{
			case 1:
				len=obj.Length();
				if(len==0)
					cout<<"List is empty\n";
				else
					cout<<"length of linkedlist is "<<len<<endl;
				break;
			case 2:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				p=obj.Find(k,x);
				if(p==1)
					cout<<"found"<<endl;
				if(p==0)
					cout<<"not found"<<endl;
				break;
			case 3:
				cout<<"enter x(value)\n";
				cin>>x;
				p=obj.Search(x);
				if(p)
					cout<<"searching is sucessful and found at "<<p<<endl;
				else
					cout<<"searching not sucessful"<<endl;
				break;
			case 4:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				obj.Delete(k,x);
				break;
			case 5:
				cout<<"enter k,x(index and value)\n";
				cin>>k>>x;
				obj.Insert(k,x);
				break;
			case 6:
				cout<<"elements in the list are:\n\n";
				obj.Output();
				break;
			default:
				cout<<"invalid choice\n";
		}
	}
	while(choice>=1&&choice<=6);
	getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/">Program to implement linked representation of Linear list using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-to-implement-linked-representation-of-linear-list-using-templates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Program for Array Based Representation of Linear List using templates</title>
		<link>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-for-array-based-representation-of-linear-list-using-templates/</link>
					<comments>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-for-array-based-representation-of-linear-list-using-templates/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Team]]></dc:creator>
		<pubDate>Thu, 27 Jan 2011 10:41:23 +0000</pubDate>
				<category><![CDATA[Data structure]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[linear list]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[linked list]]></category>
		<guid isPermaLink="false">http://studentprojects.in/?p=1212</guid>

					<description><![CDATA[<p>LinearList(int MaxLinearSize=10);<br />
~LinearList(){delete[]element;}<br />
int isEmpty()const{return length==0;}<br />
int Length()const{return length;}<br />
int Find(int k,T&#038;x)const;<br />
int Search(const T&#038;x)const;<br />
void Delete(int k,T&#038;x);<br />
void Insert(int k,const T&#038;x);<br />
void Output()const;</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-for-array-based-representation-of-linear-list-using-templates/">Program for Array Based Representation of Linear List using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<pre lang="cpp">
#include<iostream.h>
#include<constream.h>
template<class T>
class LinearList
{
	private:
		int length;
		int MaxSize;
		T *element;
	public:
		LinearList(int MaxLinearSize=10);
		~LinearList(){delete[]element;}
		int isEmpty()const{return length==0;}
		int Length()const{return length;}
		int Find(int k,T&x)const;
		int Search(const T&x)const;
		void Delete(int k,T&x);
		void Insert(int k,const T&x);
		void Output()const;
};
	template<class T>
LinearList<T>::LinearList(int MaxListSize)
{
	MaxSize=MaxListSize;
	element=new T[MaxSize];
	length=0;
}
template<class T>
int LinearList<T>::Find(int k,T&x)const
{
	if(k<1||k>length)
		return 0;
	x=element[k-1];
	return 1;
}
template<class T>
int LinearList<T>::Search(const T&x)const
{
	for(int i=0;i<length;i++)
		if(element[i]==x)
			return ++i;
	return 0;
}
	template<class T>
void LinearList<T>::Delete(int k,T&x)
{
	if(Find(k,x))
	{
		for(int i=k;i<length;i++)
			element[i-1]=element[i];
		length--;
	}
	else
		cout<<"out of bounds\n";
}
	template<class T>
void LinearList<T>::Insert(int k,const T&x)
{
	if(k<0||k>length)
		cout<<"out of bounds\n";
	if(length==MaxSize)
		cout<<"no memory\n";
	for(int i=length-1;i>=k;i--)
		element[i+1]=element[i];
	element[k]=x;
	length++;
}
template<class T>
void LinearList<T>::Output()const
{
	if(isEmpty())
		cout<<"list is empty\n";
	else
		for(int i=0;i<length;i++)
			cout<<element[i]<<"\t";
}
void menu()
{
	cout<<"\n MENU\n" ;
	cout<<"-----------\n";
	cout<<"1.Length\n";
	cout<<"2.Find\n";
	cout<<"3.Search\n";
	cout<<"4.Delete\n";
	cout<<"5.Insert\n";
	cout<<"6.Output\n";
	cout<<"-------------\n";
}
void main()
{
	int ch;
	int k,x,len,p;
	clrscr();
	LinearList <int> obj;
	do
	{
		menu();
		cout<<"enter choice\t";
		cin>>ch;
		switch(ch) {
			case 1:
				len=obj.Length();
				if(len==0)
					cout<<"List is empty\n";
				else
					cout<<"length of linearlist is "<<len<<endl;
				break;
			case 2:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				p=obj.Find(k,x);
				if(p==1)
					cout<<"found"<<endl;
				if(p==0)
					cout<<"not found"<<endl;
				break;
			case 3:
				cout<<"enter x(value)\n";
				cin>>x;
				p=obj.Search(x);
				if(p)
					cout<<"searching is sucessful and found at"<<p<<endl;
				else
					cout<<"searching not sucessful"<<endl;
				break;
			case 4:
				cout<<"enter k,x(position and value)\n";
				cin>>k>>x;
				obj.Delete(k,x);
				break;
			case 5:
				cout<<"enter k,x(index and value)\n";
				cin>>k>>x;
				obj.Insert(k,x);
				break;
			case 6:
				cout<<"elements in the list are:\n\n";
				obj.Output();
				break;
			default:
				cout<<"invalid choice\n";
				break;
		}  } while(ch>=1&&ch<=6);
		getch();
}
</pre><p>The post <a href="https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-for-array-based-representation-of-linear-list-using-templates/">Program for Array Based Representation of Linear List using templates</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/cpp-programs/cpp-data-structure/program-for-array-based-representation-of-linear-list-using-templates/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
