北美微论坛

App下载
扫码下载 App
联系我们
1框架
查看: 361|回复: 5
打印 上一主题 下一主题

[学校校园] 帮看chegg!!(回答的midterm加十分!)

[复制链接]

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

跳转到指定楼层
楼主
发表于 2014-10-4 22:03:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
深夜死在code上了,求帮忙看:
We often have occasion to work with an array that is only partially filled; furthermore, all the array positions that are used are consecutive, from element 0 onwards. In such a case, the array has a maximum size (the total number of elements that can be stored in the array), as well as the number of array positions actually being used (this would typically be stored by the programmer in a variable).
网址是:http://www.chegg.com/homework-help/questions-and-answers/often-occasion-work-array-partially-filled-furthermore-array-positions-used-consecutive-el-q1632771
蟹蟹!!

收藏收藏 分享分享 赞赞赞!赞赞赞! 踩踩踩!踩踩踩! 新浪微博微博分享
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

院士

学挖掘机哪家强???

Rank: 14Rank: 14Rank: 14Rank: 14

最佳新人常驻居民

沙发
发表于 2014-10-4 22:10:21 | 只看该作者
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool insert(int a[], int& length, int max, int position, int val);
void print(int a[],int n);
int main(){

int a[6],n=3;
a[0]=4;
a[1]=3;
a[2]=8;
print(a,n);
cout<<"insert(a,n,7,0,12)\n";
if(insert(a,n,7,0,12))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);

cout<<"insert(a,n,7,9,22)\n";
if(insert(a,n,7,9,22))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);

cout<<"insert(a,n,7,2,23)\n";
if(insert(a,n,7,2,23))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);

cout<<"insert(a,n,7,n+1,25)\n";
if(insert(a,n,7,n+1,25))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);
cout<<"insert(a,n,7,n-1,26)\n";
if(insert(a,n,7,n-1,26))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);
cout<<"insert(a,n,7,n,20)\n";
if(insert(a,n,7,n,20))
cout<<"return true\n";
else
cout<<"return false\n";
print(a,n);


system("pause");
return 0;
}
void print(int a[],int n)
{int i;
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl<<"n="<<n<<endl;
}
bool insert(int a[], int& length, int max, int position, int val){
int x = 0;
if (length + 1 > max){
return false;
}
if (position < 0 || position > length ){
return false;
}

for (x = length; x >=position; x--){
a [ x ] = a [ x-1 ];
}
a [ position ] = val;
length++;
return true;
}

评分

参与人数 1金钱 +3 收起 理由
月見藥 + 3 赞一个!

查看全部评分

人生就是悲剧
回复

使用道具 举报

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

板凳
 楼主| 发表于 2014-10-4 22:11:26 | 只看该作者
晓康打酱油 发表于 2014-10-4 21:10
#include
#include
#include

特喵的用了还是错的 不过谢谢!
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

地板
 楼主| 发表于 2014-10-4 22:13:26 | 只看该作者
答案就在里面了不好意思。。
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

院士

学挖掘机哪家强???

Rank: 14Rank: 14Rank: 14Rank: 14

最佳新人常驻居民

5#
发表于 2014-10-4 22:14:56 | 只看该作者
学工程的好牛逼的赶脚
人生就是悲剧
回复

使用道具 举报

系主任

Rank: 12Rank: 12Rank: 12

最佳新人常驻居民

6#
 楼主| 发表于 2014-10-4 22:18:11 | 只看该作者
晓康打酱油 发表于 2014-10-4 21:14
学工程的好牛逼的赶脚

伪的- - 是Math的
猫头鹰眼睛一瞪 发现事情 没有辣么简单
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

返回顶部