In: Computer Science
Situation (Data Structures and Sorting C++)
You have been employed at BmoCel, an internet service provider.
Data is sent as packets from their
server to their clients. Each packet has a fixed size of 16
alphanumeric characters. However, they are
currently having problems with managing their data transmissions.
Your bosses have asked you to
rectify the problems, in the following order:
1. The data at the server is to be stored as packets, in a
First‐In, Last‐Out manner. If there are any
errors during the data input process, the operator must be able to
go back to where the error
occurred and input the correct data going forward. Due to memory
limitations, the number of
packets that can be stored at a time is 256. Any more packets will
be discarded.
2. The packets are then to be arranged in alphanumeric order, in
the most efficient way possible.
You must verify and show programmatically the comparison of each
arrangement algorithm,
and which one proves to be the fastest for sorting the packets.
Input Data File -
cLF5dUTUJZvL1cm4 MUKcDt8s3QAh95D5 2DU7mBTukQKYtSxX faGlkKEL5Myq32eL DhOuTqr8S7dB3FHV s2cRVI3KxhucKCli KeLHG6uNatoVSXHn wsYARWi5SWifELmA N2gIpepTUTGr2WRw G1A3A0ahzqdFs8d6 r6wIM4hFMI9aNTMi Vm6CTL7j8NrffwWM TGJo9ZF4o6WwT4FJ P3AXcwYjo43ZFZow y0FZKmkCEl7paaVP mVFaJ6KSS7cjmi8a X7WHeWUdqb5DqtPB Z71NeZ9Ezsl7zV6h h2vsPoSpKOXHIocv sVqqCX1UyQYmT632 kxrVWn8hkSoPXpB3 yw3WDQbeSkk5Cu2A vajdHennHjreO0P8 YdpJ30d0ZAAM4agA EGz3oBkpv6bU9fEw 8eWE9oXik7HZ1bUR xqYSrQHQkk89bl6t ucvUn9r9etM6ABe8 LLKdgBJ99Uf0dvSL LL4W98eTOJbEJMBJ A7SAsm6BaH5ffXTK dabGd9D0zWYodn16 aKE2UguaE8SBS2q7 ZEEana6bA8jt4qUw ib7VS46VcMl0BaSS KOfahLxiScE4ktRe Cf9y7MjIdr9xDkPo Sp5dkgdQOgEnsvol jPusPE6WOc2J5WoI T9jNgtSCqMIcu58n pSgW91LMenX96a2x omyeKucr7kR3NqGT Al5ui7AnpGQnNM0B z0okwHZXCJQLpbxn ifjSf9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sOsaYvT nHJi5CH6WUJhbm5Q n4fMBgqwMEBUqRrB q2TAe7f1ZJ9BRIRn JrfBskaPxtVaSm8o KmnowZdiZmwo5msQ YiS2VRM7bYh9AAKF ln90eblkkL65rGzh 9ddCHAYwm26os5PW l32EOzFpfeZZXbBK PYjMedkryRsQF32x CIi9YD3FtPx80fod 5lJvf0s34UdVZAHF JBZ4pcyicLEO0M1a euNmFS4H14H8FK9o Gb47Zd8Q4nNB52AE
#include <bits/stdc++.h>
#include<iostream>
#include <fstream>
using namespace std;
//----------read data from file input.txt-------------
void readPacket(string packetArray[],int &size){
ifstream fp;
fp.open("input.txt",ios::in);
string str;
int i=0;
while(getline(fp, str)){
if(i<=255)
packetArray[i]=str;
else
break;
i++;
}
size=i;
}
//----print all the packet content-------------------
void display(string packetArray[],int size){
for(int i=0;i<size;i++)
cout<<packetArray[i]<<endl;
}
//all the packets stored in array
//----------First in Last out order-------------
void storePacket(stack<string> s,string packetArray[],int
size){
for(int i=0;i<size;i++)
s.push(packetArray[i]);
}
//------insertion sort of all the packets-----------
void arrangePacket(string packetArray[],int size){
int i,j;
string k;
for (i = 1; i < size; i++) {
k = packetArray[i];
j = i - 1;
while (j >= 0 &&
packetArray[j] > k) {
packetArray[j +
1] = packetArray[j];
j = j - 1;
}
packetArray[j + 1] = k;
}
}
//------main function-------------------
int main(){
string packetArray[256];
int size;
readPacket(packetArray,size);
stack<string> s;
//display(packetArray,size);
storePacket(s,packetArray,size);
arrangePacket(packetArray,size);
display(packetArray,size);
return 0;
}
//-----------------------------
//ouput
0OX0j0JWgaRhCGrR
0jEP1Rlm8pMgtiEI
1CuwzEe5WEOZaX7y
1R0AgNFSM0RsBqDM
1UqYsbTzHq0PoY4q
1VhN3v4ety9cLS8i
1Z6fJ5tPCJFnYBrc
1jhdHIZXo0DAbyDi
1m82QMtf7l3ZSBuy
23debbAmmbXvxris
2DU7mBTukQKYtSxX
2HmOEdlPUHwWN0a3
2OAr32JTgRx2Q4Cd
2RpvHmH7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