当前位置:  编程技术>移动开发
本页文章导读:
    ▪排序算法-取舍排序(简单插入排序、堆排序)        排序算法---选择排序(简单插入排序、堆排序) #include <stdio.h> void simple_select(int a[], int n) { int i,j,k,tmp; for(i=0;i<n-1;i++) { k=i; for(j=i+1;j<n;j++) .........
    ▪ 排序算法-交换排序(冒泡排序、快速排序)        排序算法---交换排序(冒泡排序、快速排序) #include <stdio.h> void bubble_sort(int a[], int n) { int i,j,tmp; for(i=0;i<n-1;i++) for(j=0;j>n-1-i;j++) if(a[j]>a[j+1].........
    ▪ 可舒卷的表视图       可伸缩的表视图 头文件:   #import <UIKit/UIKit.h> @interface TableMenuViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { NSMutableArray *itemArray; NSMutableArray *openItemArray; UITableView *m.........

[1]排序算法-取舍排序(简单插入排序、堆排序)
    来源: 互联网  发布时间: 2014-02-18
排序算法---选择排序(简单插入排序、堆排序)

#include <stdio.h>
void simple_select(int a[], int n)
{
        int i,j,k,tmp;
        for(i=0;i<n-1;i++)
        {
                k=i;
                for(j=i+1;j<n;j++)
                {
                        if(a[j]<a[k])
                                k=j;
                }
                if(k!=i)
                {
                        tmp=a[k];
                        a[k]=a[i];
                        a[i]=tmp;
                }
        }
}
void shift(int a[], int low, int high)
{
        int i=low;
        int j=2*i;
        int tmp=a[i];
        while(j<=high)
        {
                if(j<high && a[j]<a[j+1])
                        j++;
                if(tmp<a[j])
                {
                        a[i]=a[j];
                        i=j;
                        j=2*i;
                }
                else
                        break;
        }
        a[i]=tmp;
}

/*the number of elements of a is n+1*/
/*a[0] is not used*/
void heap_sort(int a[], int n)
{
        int i,tmp;
        for(i=n/2;i>=1;i--)
                shift(a,i,n);
        for(i=n;i>=2;i--)
        {
                tmp=a[i];
                a[i]=a[1];
                a[1]=tmp;
                shift(a,1,n-1);
        }
}
 

    
[2] 排序算法-交换排序(冒泡排序、快速排序)
    来源: 互联网  发布时间: 2014-02-18
排序算法---交换排序(冒泡排序、快速排序)

#include <stdio.h>
void bubble_sort(int a[], int n)
{
        int i,j,tmp;
        for(i=0;i<n-1;i++)
                for(j=0;j>n-1-i;j++)
                        if(a[j]>a[j+1])
                        {
                                tmp=a[j];
                                a[j]=a[j+1];
                                a[j+1]=tmp;
                        }
}
int partition(int a[], int low, int high)
{
        int pivot=a[low];
        while(low<high)
        {
                while(low<high && a[high]>=pivot)--high;
                a[low]=a[high];
                while(low<high && a[low]<=pivot)++low;
                a[high]=a[low];
        }
        a[low]=pivot;
        return low;
}
void qsort(int a[], int low, int high)
{
        int pivot;
        if(low<high)
        {
                pivot=partition(a,low,high);
                partition(a,low,pivot-1);
                partition(a,mid+1,high);
        }
}
void quick_sort(int a[], int n)
{
        qsort(a,0,n-1);
}
 

    
[3] 可舒卷的表视图
    来源: 互联网  发布时间: 2014-02-18
可伸缩的表视图

头文件:

 

#import <UIKit/UIKit.h>

@interface TableMenuViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
	NSMutableArray *itemArray;
	NSMutableArray *openItemArray;
	UITableView *menuTable;
}

@property (nonatomic, retain) NSMutableArray *itemArray;
@property (nonatomic, retain) NSMutableArray *openItemArray;
@property (nonatomic, retain) IBOutlet UITableView *menuTable;

- (void)readPlistToArray;

@end

 

实现文件:

 

#import "TableMenuViewController.h"

@implementation TableMenuViewController

@synthesize itemArray, openItemArray, menuTable;

- (void)viewDidLoad {
	[super viewDidLoad];
	self.itemArray = [NSMutableArray arrayWithCapacity:0];
	self.openItemArray = [NSMutableArray arrayWithCapacity:0];
	[self readPlistToArray];
}

- (void)readPlistToArray {
	if ([self.itemArray count]) {
		[self.itemArray removeAllObjects];
	}
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"MenuOrder" ofType:@"plist"];
	NSArray *array = [NSArray arrayWithContentsOfFile:path];
	
	for (int i = 0; i < [array count]; i++) {
		NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
		[dic setObject:@"0" forKey:@"level"];
		[dic setObject:[[array objectAtIndex:i] objectAtIndex:0] forKey:@"name"];
		[self.itemArray addObject:dic];
		
		for (int j = 0; j < [self.openItemArray count]; j++) {
			if ([[[self.openItemArray objectAtIndex:j] objectForKey:@"name"] 
					 isEqualToString:[[array objectAtIndex:i] objectAtIndex:0]]) {
				NSArray *ary = [array objectAtIndex:i];
				for (int k = 1; k < [ary count]; k++) {
					NSMutableDictionary *menuDic = [NSMutableDictionary dictionaryWithCapacity:0];
					[menuDic setObject:@"2" forKey:@"level"];
					[menuDic setObject:[ary objectAtIndex:k] forKey:@"name"];					
					[self.itemArray addObject:menuDic];	
				}
			}
		}
	}
}

#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
	return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return [self.itemArray count];
}

- (NSInteger)tableView:(UITableView *)tableView 
indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return [[[self.itemArray objectAtIndex:[indexPath row]] objectForKey:@"level"] intValue];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {	
	static NSString *CellIdentifier = @"Cell";
	
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
	}
	
	NSDictionary *dic = [self.itemArray objectAtIndex:[indexPath row]];
	
	if(![[dic objectForKey:@"level"] intValue])
	{
		cell.selectionStyle = UITableViewCellSelectionStyleNone;		
		UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menubackgroud.png"]];
		[cell setBackgroundView:imageView];		
	}
	else {
		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
		UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"itembackgroud.png"]];
		[cell setBackgroundView:imageView];		
	}
	cell.textLabel.text = [dic objectForKey:@"name"];
	
	return cell;
}

#pragma mark -
#pragma mark Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSDictionary *dic = [self.itemArray objectAtIndex:[indexPath row]];
	NSString *name = [dic objectForKey:@"name"];
	
	if(![[dic objectForKey:@"level"] intValue])
	{
		for (int i = 0; i < [self.openItemArray count]; i++) {
			if ([[[self.openItemArray objectAtIndex:i] objectForKey:@"name"] isEqualToString:name]) {
				[self.openItemArray removeObjectAtIndex:i];
				[self readPlistToArray];
				[self.menuTable reloadData];
				
				return;
			}
		}
		[self.openItemArray addObject:dic];
		[self readPlistToArray];
		[self.menuTable reloadData];
	}
	else {
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:(@"%@", name) delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 44;
}

- (void)dealloc {
	[itemArray release];
	[openItemArray release];
	[menuTable release];
	
	[super dealloc];
}

@end

 

示例图:



    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android提高之MediaPlayer播放网络视频的实现方法... iis7站长之家
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3