Skip to content

Commit

Permalink
二叉搜索树ok
Browse files Browse the repository at this point in the history
  • Loading branch information
toly1994328 committed Nov 26, 2018
1 parent a7e54ee commit e49d74e
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.toly1994.ds4android.activity.home;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.toly1994.ds4android.R;
import com.toly1994.ds4android.activity.ArrayChartActivity;
import com.toly1994.ds4android.activity.BinarySearchActivity;
import com.toly1994.ds4android.activity.LinkedChartActivity;
import com.toly1994.ds4android.activity.QueueActivity;
import com.toly1994.ds4android.activity.SingleLinkedChartActivity;
import com.toly1994.ds4android.activity.StackActivity;

import java.util.List;

public class HomeRVAdapter extends RecyclerView.Adapter<HomeRVAdapter.MyViewHolder> {
private Context mContext;
private List<Integer> mData;

public HomeRVAdapter(Context context, List<Integer> data) {
mContext = context;
mData = data;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_of_cade, parent, false);
return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.mIvCover.setImageResource(mData.get(position));

holder.mIvCover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (position) {
case 0:
mContext.startActivity(new Intent(mContext, ArrayChartActivity.class));
break;
case 1:
mContext.startActivity(new Intent(mContext, SingleLinkedChartActivity.class));
break;
case 2:
mContext.startActivity(new Intent(mContext, LinkedChartActivity.class));
break;
case 3:
mContext.startActivity(new Intent(mContext, StackActivity.class));
break;
case 4:
mContext.startActivity(new Intent(mContext, QueueActivity.class));
break;
case 5:
mContext.startActivity(new Intent(mContext, BinarySearchActivity.class));
break;

}

}
});

}

@Override
public int getItemCount() {
return mData.size();
}

class MyViewHolder extends RecyclerView.ViewHolder {
public CardView mCvContent;
public ImageView mIvCover;

public MyViewHolder(View itemView) {
super(itemView);
mCvContent = itemView.findViewById(R.id.cv_content);
mIvCover = itemView.findViewById(R.id.iv_cover);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.toly1994.ds4android.ds.impl.task;


import com.toly1994.ds4android.ds.impl.chart.SingleLinkedChart;
import com.toly1994.ds4android.ds.itf.IStack;

/**
* 作者:张风捷特烈
* 时间:2018/11/23 0017:22:40
* 邮箱:[email protected]
* 说明:栈的链表式集合实现
*/
public class SingleLinkedStack<E> implements IStack<E> {

private SingleLinkedChart<E> mSingleLinkedChart;

public SingleLinkedStack() {
mSingleLinkedChart = new SingleLinkedChart<>();
}


@Override
public int size() {
return mSingleLinkedChart.size();
}

@Override
public int capacity() {
return mSingleLinkedChart.size();
}

@Override
public boolean isEmpty() {
return mSingleLinkedChart.isEmpty();
}

@Override
public void push(E el) {
mSingleLinkedChart.add(el);
}

@Override
public E pop() {
return mSingleLinkedChart.remove();
}

@Override
public E peek() {
return mSingleLinkedChart.get(0);
}
}

0 comments on commit e49d74e

Please sign in to comment.