Code: Select all
#include <stdint.h>
class List_t {
struct Node_t {
int32_t N;
Node_t *Next, *Prew;
Node_t():Next(0),Prew(0),N(0) {}
Node_t(Node_t *next,Node_t *prew,int32_t n):Next(next),Prew(prew),N(n) {}
~Node_t() {}
} *Front, *Back;
public:
List_t() {}
List_t(int32_t n) {
Front = new Node_t(0,0,n);
Back = Front;
}
~List_t() {}
void push_back(int32_t n) {
Back->Next = new Node_t(0,Back,n);
Back = Back->Next;
}
void push_front(int32_t n) {
Back->Next = new Node_t(Front,0,n);
Front = Front->Prew;
}
void pop_back() {
if(count() != 0) {
Back = Back->Prew;
delete Back->Next;
Back->Next = 0;
}
}
void pop_front() {
if(count() != 0) {
Front = Front->Next;
delete Front->Prew;
Back->Prew = 0;
}
}
int32_t get_back() {
if(count() != 0) return Back->N;
else return 0;
}
int32_t get_front() {
if(count() != 0) return Front->N;
else return 0;
}
uint32_t count() {
uint32_t i = 1;
for(Node_t *temp = Front; temp->Next != 0; temp = temp->Next, i++) {}
return i;
}
};
Im pretty tired and the code might look somewhat scrambled and probably is, but for now i just need to get an answer to that one question.
Allso youll notice that the code isnt commented, but i think it selfexplainatary.
Hope you can help.
Goodnight