Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <class T>
- class List{
- public:
- //*****************************************************//
- struct el{
- T value;
- el *next;
- el(T&w):value(w),next(NULL){}; // lista inicjalizacyjna
- };
- //*****************************************************//
- //*************************POLA************************//
- el *head; // glowa
- //*****************************************************//
- //*************************METODY**********************//
- List(); //konstruktor
- bool IsEmpty(void); // sprawdza czy pusta
- void Add(T val); // dodaje wartosc
- T GetVal(int idx); // pobeira nty element (tutaj lepiej by bylo przeciazyc []
- //zeby moc skorzystac z qsort
- //*****************************************************//
- };
- template <class T>
- List<T>::List(){
- head=NULL;
- }
- template <class T>
- bool List<T>::IsEmpty(void){
- return head==NULL;
- }
- template <class T>
- void List<T>::Add(T val){
- if(this->IsEmpty()){
- head=new el(val);
- }
- else {
- el* tmp=head;
- while(tmp->next!=NULL) tmp=tmp->next;
- el* new_el = new el(val);
- tmp->next = new_el;
- }
- }
- template <class T>
- T List<T>::GetVal(int idx){
- el *tmp = head;
- //if((tmp->next==NULL)&&idx>0) return -1;
- while(idx){
- idx--;
- tmp=tmp->next;
- if(idx>0&&tmp->next==NULL) return -1;
- }
- return tmp->value;
- }
- int main()
- {
- List<int> moja_lista();
- moja_lista.IsEmpty();
- }
Advertisement
Add Comment
Please, Sign In to add comment