Professional Documents
Culture Documents
Algoritem Dhe Programim I Avancuar - Laborator 2
Algoritem Dhe Programim I Avancuar - Laborator 2
INFORMACIONIT
Punë Laboratori nr 2
Punoi:
Drejtimi:
Kodi ne C++
Linked_list.cpp
#include "Linked_list.h"
Linked_list< T >::Linked_list()
_pHead->_pNext = _pHead;
_pHead->_pPrev = _pHead;
_length = 0;
_length = L.size();
_pHead->_pNext = _pHead;
_pHead->_pPrev = _pHead;
if (!L.empty())
position p = L.last();
{
insert(L.read(p), begin());
p = L.previous(p);
Linked_list< T >::~Linked_list()
while(!empty())
erase(begin());
delete _pHead;
if (empty())
_length = 0;
return(_pHead == _pHead->_pNext);
return (_pHead->_pNext);
return (_pHead->_pPrev);
return(p->_pNext);
if (p != _pHead)
return(p->_pPrev);
return(p == _pHead);
}
if (!end(p))
return(p->_value);
if (!end(p))
p->_value = a;
t->_value = a;
t->_pNext = p;
t->_pPrev = p->_pPrev;
p->_pPrev->_pNext = t;
p->_pPrev = t;
_length++;
}
template< class T >
p->_pPrev->_pNext = p->_pNext;
p->_pNext->_pPrev = p->_pPrev;
delete p;
template<class T>
if (this != &L)
_length = L.size();
_pHead->_pNext = _pHead;
_pHead->_pPrev = _pHead;
if (!L.empty())
position p = L.last();
for (int i=0; i < L.size(); i++)
insert(L.read(p), begin());
p = L.previous(p);
return *this;
template<class T>
if (L.size() != _length)
return false;
position p, pL;
p = begin();
pL = L.begin();
while (!end(p))
if (p->_value != pL->_value)
return false;
p = p->_pNext;
pL = pL->_pNext;
}
return true;
int count=0;
position *p;
_pHead=begin();;
for(int i=0;i<_length;i++){
if(_pHead->_value==a){
count++;
*p=_pHead;
// cout<<*p<<endl;
// cout<<_pHead->_value<<endl;
_pHead=_pHead->_pNext ;
return *p;
}
template< class T >
position p=begin();;
_pHead=begin();
value_type a;
for(int i=0;i<_length;i++){
for(int j=i;j<_length-1;j++){
_pHead=_pHead->_pNext;
if(_pHead->_value<p->_value){
a=_pHead->_value;
_pHead->_value=p->_value;
p->_value=a;
p=p->_pNext;
_pHead=p;
position p=list.begin();
while(!list.end(p)){
_pHead=last();
_pHead=_pHead->_pNext;
insert(p->_value,_pHead->_pNext);
p=p->_pNext;
rendit();
Linked_list.h
#ifndef _LINKED_LIST_H
#define _LINKED_LIST_H
#include <iostream>
struct List_node{
T _value;
List_node<T> * _pPrev;
List_node<T> * _pNext;
};
template<class T>
class Linked_list
public:
typedef T value_type;
// konstruktoret
Linked_list();
Linked_list(int);
// konstruktori i kopjes
Linked_list(const Linked_list<T>& );
//destruktori
~Linked_list();
// operatoret
void create();
void erase(position);
return _length;
};
// overload i operatoreve
position p;
p = l.begin();
os << "[";
while (!l.end(p))
if (p != l.begin())
else
os << l.read(p);
p = l.next(p);
return os;
private:
List_node<T> * _pHead;
};
#endif // _LINKED_LIST_H
Main.cpp
#include "Linked_list.h"
#include <iostream>
int main()
Linked_list<int>::position iter;
int x;
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());
list2 = list1;
if (list1 == list2)
else
list2.erase(list2.begin());
if (list1 == list2)
else
list1.rendit();
list1.bashkangjit(list2);