-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeList.java
More file actions
114 lines (78 loc) · 1.46 KB
/
ExchangeList.java
File metadata and controls
114 lines (78 loc) · 1.46 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
class node
{
Exchange data;
node next;
public node(Exchange e)
{
data=e;
next=null;
}
}
public class ExchangeList {
node head=null;
public int getCount()
{
node temp = head;
int count = 0;
while (temp != null)
{
count++;
temp = temp.next;
}
return count;
}
void push(Exchange new_data)
{
/* 1 & 2: Allocate the Node &
Put in the data*/
node new_node = new node(new_data);
if(head==null)
{
head=new_node;
return;
}
/* 3. Make next of new Node as head */
new_node.next = head;
/* 4. Move the head to point to new Node */
head = new_node;
/* 4. Move the head to point to new Node */
}
public Exchange getExchange(int i)
{
node temp=head;
int c=this.getCount();
for(int n=c;n>(c-i);i--)
{
temp=temp.next;
}
return temp.data;
}
public void reverse() {
node prev = null;
node current = head;
node next = null;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
head= prev;
}
public String printalll()
{
String h=new String();
int y=getCount();
int q=0;
for(q=0;q<(y-1);q++)
{
Exchange f=this.getExchange(q);
h = h + f.idd;
h = h + ",";
h = h + " ";
}
Exchange f=this.getExchange(q);
h = h + f.idd;
return h;
}
}