forked from joharbatta/DataStructure-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskipMdelN.java
More file actions
69 lines (69 loc) · 1.54 KB
/
Copy pathskipMdelN.java
File metadata and controls
69 lines (69 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.*;
public class skipMdelN
{
static class node
{
int data;
node next;
node(int d)
{
this.data=d;
next=null;
}
}
static node head;
public static node insert(node head,int data)
{
node temp=new node(data);
if(head==null)
{
head=temp;
}
else
{
node p=head;
while(p.next!=null)
{
p=p.next;
}
p.next=temp;
}
return head;
}
public static void display(node head,int a,int b)
{
node p=head;
while(p.next!=null)
{
int e=0;
int f=0;
while(e!=a && p.next!=null)
{
System.out.print(p.data+" ");
p=p.next;
e++;
}
while(f!=b && p.next!=null)
{
p=p.next;
f++;
}
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num=0;
System.out.println("please enter the entries and prss and -1 to exit");
while(num!=-1)
{
num=sc.nextInt();
head= insert(head,num);
}
System.out.println("enter m-sKip");
int a=sc.nextInt();
System.out.println("enter n-Delete");
int b=sc.nextInt();
display(head,a,b);
}
}