/ Published in: C++
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
struct list {
elementtype value;
struct list *next;
};
typedef list *element;
element FirstL(list *L)
{
return(L->next);
}
element EndL(list *L)
{
list *l;
l=L;
while (l->next != NULL) {
l=l->next;
}
return(l);
}
element NextL(element p, list *L)
{
if (p->next == NULL) {
cout << "Nepostojeci element NEXT";
exit(0);
}
else {
list *l;
l=p->next;
return(l);
}
}
element PreviousL(element p, list *L)
{
list *l;
l=L;
while ((l->next != NULL) && (l->next != p))
l=l->next;
if (l->next != NULL)
return(l);
else {
cout << "Nepostojeci element PREV";
system("pause");
exit(0);
}
}
element LocateL(elementtype x, list *L)
{
list *l;
l=L;
while ((l->next != NULL) && (l->next->value != x))
l=l->next;
return(l);
}
void InsertL(elementtype x, element p, list *L)
{
list *l;
l=new list;
l->next=p->next;
p->next=l;
l->value = p->value;
p->value = x;
}
void DeleteL(element p, list *L)
{
element l;
p=PreviousL(p,L);
if (p->next != NULL) {
l=p->next;
p->next=p->next->next;
delete l;
}
else {
cout << "Nepostojeci element DELETE";
system("pause");
exit(0);
}
}
elementtype RetrieveL(element p, list *L)
{
if (p->next != NULL) {
elementtype x;
x=p->value;
return(x);
}
else {
cout << "Nepostojeci element RETRIVER";
system("pause");
exit(0);
}
}
void DeleteAllL(list *L)
{
element l;
while (L->next != NULL) {
l=L->next;
L->next = L->next->next;
delete l;
}
}
void InitL(list *L)
{
list *l;
l = new list;
L->next=l;
l->next=NULL;
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                