Answer:
All three of them are linear Data Structures.
A stack is a FILO(First In Last Out) or LIFO(Last In First Out) type data structure means first inserted element will be the last one to be removed form the stack.Insertion and Deletion is from one end only called head.
ex:-A stack of books on the shelf.
A queue is FIFO(First In First Out) type means the first inserted element will be the first one to be removed.In queue insertion is from the back or tail and removal of elements is done form the front.
ex:-A queue at the ticket counter.
In array each element stored is given an index, by which we can be access the element very easily. We can use this index to modify or store element at that index of the array. i.e any object can be accessed with the right index, unlike queue and stack.
We can access only the front and back in the queue.In stack we can access only the top but in array we can access any element with the index.
Answer:
I am doing it with python.
Explanation:
nums = '9 -8 -7 -6 -5 -4 -2 0 1 5 9 6 7 4'
myfile = open('data.txt', 'w')
myfile.write(nums)
myfile.close()
myfile = open('data.txt', 'r')
num1 = (myfile.read())
num1 = num1.split()
print(num1)
print(type(num1))
for x in num1:
x = int(x)
if x < 0:
minus = open('dataminus.txt', 'a')
minus.write(str(x) + ' ')
minus.close()
elif x>= 0:
plus = open('dataplus.txt', 'a')
plus.write(str(x)+' ')
plus.close()
Answer:
38 cents on the dollar means that the cost is 38%. So for each of the costs, multiply by 0.38 (38%) to get the cost.
$3459*0.38=$1314.42
$2976.81*0.38 = 1131.1878 or about $1131.19
etc.
Answer:
import java.util.*;
public class Create_set
{
public static void main(String args[])
{
Set<Integer> hset = new HashSet<Integer>(); //creating set using hashset of Integer type
hset.add(10); //add method add members to set
hset.add(20);
hset.add(30);
hset.add(40);
System.out.println(hset); //printing the set
}
}
OUTPUT :
[20,40,10,30]
Explanation:
The above code is implemented through java language. First a collection object is created using Set interface. Then that interface is implemented using Hashset class. As they are of generic datatype, Integer type is declared for this object. Then using add() method elements of the set are added and at last they are printed.
Set is an unordered collection which means elements can't be accessed through their particular position and no duplicate values are stored in sets.