数据结构C语言编程
#include"stdio.h"
#include
#include"time.h"
intmain(intargv,char*argc[]){
doublex[10]={0.0,};
inti;
srand((unsigned)time(NULL));
while(rand()%10000!=0){//
for(i=0;i<9;x[i++]=x[i+1]);
x[9]=rand()/32767.0*100000;//模拟采集数据
for(i=0;i<10;printf("%10.3f\n",x[i++]));//输出最后10个数
return0;
运行样例:
本回答由网友推荐
数据结构JAVA 线性表编程代码
import java.util.List;import java.util.LinkedList;public class SortList {public static void sort(List list1,List list2,List list3){int i=0,j=0;//Iterator it1 = list1.iterator();//本来准备用迭代器的,没时间,就这样了//Iterator it2 = list2.iterator();while(i<=list1.size()-1&&j<=list2.size()-1){if(list1.get(i).compareTo(list2.get(j))>0){list3.add(list3.size(),list2.get(j));j++;}else {list3.add(list3.size(),list1.get(i));i++;while(i<=list1.size()-1){list3.add(list3.size(), list1.get(i));while(j<=list2.size()-1){list3.add(list3.size(), list2.get(j));public static void main(String args[]){LinkedList ll1,ll2,ll3;ll1 = new LinkedList();ll2 = new LinkedList();ll3 = new LinkedList();ll1.addFirst(new Long(5));ll2.addFirst(new Long(4));ll1.addFirst(new Long(3));ll2.addFirst(new Long(2));ll1.addFirst(new Long(1));System.out.print("表1:");for(Long l : ll1){System.out.print(l+" ");System.out.print("\n表2:");for(Long l : ll2){System.out.print(l+" ");SortList.sort(ll1, ll2, ll3);System.out.print("\n表3:");for(Long l : ll3){System.out.print(l+" ");}注意List中的所有元素都要求实现Comparable接口,由这个接口的子类来指定比较的方法。测试中用的是已经实现了的Long类型