From a69a65622ae26ce2b145b28455aedc5ec50e6e01 Mon Sep 17 00:00:00 2001 From: juanyudha12 Date: Mon, 21 Sep 2015 21:39:26 +0700 Subject: [PATCH] Update list.cpp --- LinkedList/list.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/LinkedList/list.cpp b/LinkedList/list.cpp index e69de29..110a0f1 100644 --- a/LinkedList/list.cpp +++ b/LinkedList/list.cpp @@ -0,0 +1,36 @@ +void deleteFirst(list &l, listElement *&p) +{ + if(l.first==0) + { + return; + } + else + { + p=l.first; + l.first=p->next; + } +} + +void deleteLast(list &l, listElement *&p) +{ + if(l.first==0) + { + return; + } + else + { + listElement *it = l.first; + listElement *prev = it; + + while(it->next!=0) + { + prev=it; + it=it->next; + } + + if(it==l.first) + l.first=0; + prev->next=0; + p=it; + } +}