Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int example5(SLL<Integer> lista)
- {
- /*
- Дадена е линеарно поврзана листа. Да се напише функција која од листата ќе ги
- избрише сите елементи кои во info полето имаат парен број. Како резултат функцијата
- да враќа колку јазли биле избришани.
- */
- if(lista.first == null)
- {
- return 1;
- }
- int i = 0;
- SLLNode<Integer> current = lista.first;
- SLLNode<Integer> prev = null;
- while(current != null)
- {
- if(current.element % 2 == 0)
- {
- i++;
- SLLNode<Integer> sled = current.succ;
- if(prev == null)
- {
- lista.first = sled;
- current = lista.first;
- }
- else
- {
- prev.succ = sled;
- current = prev.succ;
- }
- }
- else
- {
- prev = current;
- current = current.succ;
- }
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement