Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package MID;
- /**
- *
- * @author acer
- */
- public class Mid {
- Node head;
- int cir[];
- int start;
- int size;
- public Mid(int[] array)
- {
- //edit to create Linked List with global head from given array
- head=new Node(array[0],null);
- Node tail=head;
- for(int i=1;i<array.length;i++){
- Node mn=new Node(array[i],null);
- tail.next=mn;
- tail=mn;
- }
- }
- public void printList(){
- // TO DO
- for(Node n=head;n!=null;n=n.next){
- System.out.print(n.element+" ");
- }
- System.out.println();
- }
- public Mid(int[] array3, int st, int sz)
- {
- cir=new int[array3.length];
- //Creates global circular array cir from given array.
- int k=st;
- start=st;
- size=sz;
- for(int i=0;i<sz;i++){
- cir[k]=array3[k];
- //System.out.println("inserting "+cir[k]);
- k=(k+1)%cir.length;
- }
- }
- public void pattern()
- {
- //you can use the System.out.println line only twice
- //Node succ=null;
- for(Node n=head;n!=null;n=n.next){
- if(n.next!=null && n.next.next!=null ){
- System.out.println("my elem is "+n.element+" and product of two of my neighbours = "+Integer.parseInt(n.next.element+"")*Integer.parseInt(n.next.next.element+""));
- }
- else{
- System.out.println("my elem is "+n.element+" and i have no neighbours");
- //System.out.println("My elem is "+n.next.element+" and i have no neighbours");
- }
- }
- }
- public void occurrence(int i)
- {
- int start=0;
- int foundTimes=0;
- boolean b=false;
- int index=0;
- int count=0;
- /* edit */
- for(Node n=head;n!=null;n=n.next){
- if(n.element.equals(i)){
- if(b==false){
- start=count;
- b=true;
- }
- foundTimes=count;
- }
- count++;
- }
- for(Node n=head;n!=null;n=n.next){
- if(index==start){
- System.out.println(n.element+" was first found in "+index);
- }
- if(index==foundTimes){
- System.out.println(n.element+" was last found in "+index);
- }
- index++;
- }
- }
- public void sort()
- {
- int p=start;
- for(int i=0;i<size;i++){
- int q=(p+1)%cir.length;
- for(int j=i+1;j<size;j++){
- if(cir[q]<cir[p]){
- //System.out.println(cir[q]+"<"+cir[p]);
- int temp=cir[p];
- cir[p]=cir[q];
- cir[q]=temp;
- //System.out.println(cir[q]+"<"+cir[p]);
- }
- q=(q+1)%cir.length;
- }
- p=(p+1)%cir.length;
- }
- /*
- int [] lin=new int[cir.length];
- int p=start;
- for(int i=0;i<cir.length;i++){
- lin[i]=cir[p];
- p=(p+1)%cir.length;
- }
- for(int i=0;i<size;i++){
- for(int j=i+1;j<size;j++){
- if(lin[j]<lin[i]){
- int temp=lin[i];
- lin[i]=lin[j];
- lin[j]=temp;
- }
- }
- }
- for(int i=0;i<cir.length;i++){
- cir[p]=lin[i];
- p=(p+1)%cir.length;
- }
- */
- //sorts the circular array
- }
- public void print()
- {
- System.out.println();
- //System.out.println("circ print");
- //prints the circulate array
- int k=start;
- for(int i=0;i<cir.length;i++){
- //System.out.println("kkkkk");
- System.out.print(cir[i]+",");
- //k=(k+1)%cir.length;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement