class
GFG
{
static
class
node
{
char
data;
node next;
};
static
node add(
char
data)
{
node newnode =
new
node();
newnode.data = data;
newnode.next =
null
;
return
newnode;
}
static
void
print(node head)
{
while
(head !=
null
)
{
System.out.print(head.data +
" -> "
);
head = head.next;
}
System.out.print(
"null"
);
}
static
boolean
isSpecialChar(
char
ch)
{
if
(ch >=
'a'
&& ch <=
'z'
)
return
false
;
if
(ch >=
'A'
&& ch <=
'Z'
)
return
false
;
if
(ch >=
'0'
&& ch <=
'9'
)
return
false
;
return
true
;
}
static
node removeFromLL(node head)
{
node curr = head; node prev = head;
while
(curr !=
null
&&
isSpecialChar(curr.data))
{
node temp = curr;
head = curr.next;
curr = curr.next;
temp =
null
;
}
prev = head;
while
(curr !=
null
)
{
while
(curr !=
null
&&
isSpecialChar(curr.data))
{
node temp = curr;
prev.next = curr.next;
curr = curr.next;
temp =
null
;
}
if
(curr ==
null
)
break
;
prev = curr;
curr = curr.next;
}
return
head;
}
public
static
void
main(String[] args)
{
node head =
null
;
head = add(
'('
);
head.next = add(
'G'
);
head.next.next = add(
'E'
);
head.next.next.next = add(
'E'
);
head.next.next.next.next = add(
'*'
);
head.next.next.next.next.next = add(
'K'
);
head.next.next.next.next.next.next = add(
'S'
);
head.next.next.next.next.next.next.next = add(
'*'
);
head = removeFromLL(head);
print(head);
}
}