Advertisement
hgr24

Untitled

Mar 29th, 2022
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. class Queue
  4. {
  5. int q[],f=0,r=0,size;
  6. void insert(int n)
  7. {
  8. Scanner in = new Scanner(System.in);
  9. q=new int[10];
  10. for(int i=0;i<n;i++)
  11. {
  12. System.out.print("\nEnter " + i + " element: ");
  13. int ele=in.nextInt();
  14. if(r+1>10)
  15. {
  16. System.out.println("\nQueue is full \nLost Packet: "+ele);
  17. break;
  18. }
  19. else
  20. {
  21.     {
  22.         r++;
  23.         q[i]=ele;
  24. }
  25. }}
  26. }
  27.  
  28. void delete()
  29. {
  30. Scanner in = new Scanner(System.in);
  31. Thread t=new Thread();
  32. if(r==0)
  33. System.out.print("\nQueue empty ");
  34. else
  35. {
  36. for(int i=f;i<r;i++)
  37. {
  38. try
  39. {
  40. t.sleep(1000);
  41. }
  42. catch(Exception e){}
  43. System.out.print("\nLeaked Packet: "+q[i]);
  44. f++;
  45. }
  46. }
  47. System.out.println();
  48. }
  49. }
  50. class Leaky extends Thread
  51. {
  52. public static void main(String ar[]) throws Exception
  53. {
  54.     Queue q=new Queue();
  55.     Scanner src=new Scanner(System.in);
  56.     System.out.println("\nEnter the packets to be sent:");
  57.     int size=src.nextInt();
  58.     q.insert(size);
  59.     q.delete();
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement