-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7e54ee
commit e49d74e
Showing
2 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/toly1994/ds4android/activity/home/HomeRVAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/toly1994/ds4android/ds/impl/task/SingleLinkedStack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |