Lab2

```UNIVERSITETI POLITEKNIK I TIRANES FAKULTETI I TEKNOLOGJISE DHE
INFORMACIONIT
DEPARTAMENTI ELEKTRONIKES DHE TELEKOMUNIKACIONIT
Pun&euml; Laboratori nr 2
Tema : Listat e lidhura me pointera
L&euml;nda: Algoritmik&euml; dhe Programim i Avancuar
Punoi: Darla Zhuka
Drejtimi: Elektronike 2B
Kodi ne C++
using namespace std;
template&lt; class T &gt;
{
_length = 0;
}
template&lt; class T &gt;
{
_length = L.size();
if (!L.empty())
{
position p = L.last();
for (int i=0; i &lt;= L._length; i++)
{
p = L.previous(p);
}
}
}
template&lt; class T &gt;
{
while(!empty())
erase(begin());
}
template&lt; class T &gt;
{
if (empty())
_length = 0;
}
template&lt; class T &gt;
{
}
template&lt; class T &gt;
{
}
template&lt; class T &gt;
{
}
template&lt; class T &gt;
{
return(p-&gt;_pNext);
}
template&lt; class T &gt;
{
return(p-&gt;_pPrev);
}
template&lt; class T &gt;
bool Linked_list&lt; T &gt;::end(position p) const
{
}
template&lt; class T &gt;
{
if (!end(p))
return(p-&gt;_value);
}
template&lt; class T &gt;
void Linked_list&lt; T &gt;::write(const value_type &amp;a, position p)
{
if (!end(p))
p-&gt;_value = a;
}
template&lt; class T &gt;
void Linked_list&lt; T &gt;::insert(const value_type &amp;a, position p)
{
position t = new List_node&lt;T&gt;;
t-&gt;_value = a;
t-&gt;_pNext = p;
t-&gt;_pPrev = p-&gt;_pPrev;
p-&gt;_pPrev-&gt;_pNext = t;
p-&gt;_pPrev = t;
_length++;
}
template&lt; class T &gt;
{
if (!empty() &amp;&amp; !end(p))
{
p-&gt;_pPrev-&gt;_pNext = p-&gt;_pNext;
p-&gt;_pNext-&gt;_pPrev = p-&gt;_pPrev;
delete p;
}
}
template&lt;class T&gt;
{
if (this != &amp;L)
{
_length = L.size();
//cout &lt;&lt; L.empty();
//cout &lt;&lt; L.size();
if (!L.empty())
{
position p = L.last();
for (int i=0; i &lt; L.size(); i++)
p = L.previous(p);
}
}
}
return *this;
}
template&lt;class T&gt;
{
if (L.size() != _length)
return false;
position p, pL;
p = begin();
pL = L.begin();
while (!end(p))
{
if (p-&gt;_value != pL-&gt;_value)
return false;
p = p-&gt;_pNext;
pL = pL-&gt;_pNext;
}
return true;
}
template&lt; class T &gt;
{
int count=0;
position *p;
for(int i=0;i&lt;_length;i++){
count++;
//
cout&lt;&lt;*p&lt;&lt;endl;
}
}
cout&lt;&lt;&quot;Vlera &quot;&lt;&lt;a&lt;&lt;&quot; gjendet &quot;&lt;&lt;count&lt;&lt;&quot; here ne liste.&quot;;
return *p;
}
template&lt; class T &gt;
position p=begin();;
value_type a;
for(int i=0;i&lt;_length;i++){
for(int j=i;j&lt;_length-1;j++){
p-&gt;_value=a;
}
}
p=p-&gt;_pNext;
}
}
template&lt; class T &gt;
position p=list.begin();
while(!list.end(p)){
p=p-&gt;_pNext;
}
rendit();
}
#include &lt;iostream&gt;
using namespace std;
template &lt;class T&gt;
struct List_node{
T _value;
List_node&lt;T&gt; * _pPrev;
List_node&lt;T&gt; * _pNext;
};
template&lt;class T&gt;
{
public:
typedef T value_type;
typedef List_node&lt;T&gt;* position;
// konstruktoret
// konstruktori i kopjes
//destruktori
// operatoret
void create();
bool empty() const;
void write(const value_type &amp;, position);
position begin() const;
position last() const;
bool end(position) const;
position next(position) const;
position previous(position) const;
position gjej(const value_type &amp;);// kerkesa A
void rendit();// kerkesa B
void insert(const value_type &amp;, position);
void erase(position);
int size() const
{
return _length;
};
bool operator==(const Linked_list&lt;T&gt; &amp;) const; // kontrollon dy lista per barazi
friend std::ostream&amp; operator&lt;&lt;(ostream&amp; os, const Linked_list&lt;T&gt; &amp;l)
{
position p;
p = l.begin();
os &lt;&lt; &quot;[&quot;;
while (!l.end(p))
{
if (p != l.begin())
os &lt;&lt; &quot;, &quot; &lt;&lt; l.read(p);
else
p = l.next(p);
}
os &lt;&lt; &quot;]&quot; &lt;&lt; endl;
return os;
}
private:
int _length; // gjatesia e listes
};
Main.cpp
#include &lt;iostream&gt;
using namespace std;
int main()
{
int x;
/* shtohen kater elementet ne listen list1 */
x = 1;
list1.insert(x, list1.begin());
x = 2;
list1.insert(x, list1.begin());
x = 3;
list1.insert(x, list1.begin());
list1.insert(3, list1.begin());
x = 4;
list1.insert(x, list1.begin());
/* afishimi i elementeve te list1 */
cout &lt;&lt; &quot;list1=&quot; ;
cout &lt;&lt; list1;
list2 = list1;
cout &lt;&lt;endl&lt;&lt; &quot;Pasi list2=list1, list2=&quot;;
cout &lt;&lt; list2;
/* perdoret operatori i bere overload == */
if (list1 == list2)
cout &lt;&lt; &quot;list1 == list2&quot; &lt;&lt; endl;
else
cout &lt;&lt; &quot;list1 != list2&quot; &lt;&lt; endl;
list2.erase(list2.begin());
cout &lt;&lt; &quot;Pas fshirjes se elementit te pare, list2=&quot;;
cout &lt;&lt; list2;
/* perdoret operatori i bere overload == */
if (list1 == list2)
cout &lt;&lt; &quot;list1 == list2&quot; &lt;&lt; endl;
else
cout &lt;&lt; &quot;list1 != list2&quot; &lt;&lt; endl;
cout&lt;&lt;endl&lt;&lt;&quot;Pozicioni i fundit: &quot;&lt;&lt;list1.gjej(3)&lt;&lt;endl;
list1.rendit();
cout&lt;&lt;&quot;Lista e renditur: &quot;&lt;&lt;list1;
list1.bashkangjit(list2);
cout &lt;&lt;&quot;Lista e bashkengjitur: &quot;&lt;&lt;list1;
}
```