cnt_list.cpp

  name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-5572165936844014&dt=1194442938015&lmt=1194190197&format=336x280_as&output=html&correlator=1194442937843&url=file%3A%2F%2F%2FC%3A%2FDocuments%2520and%2520Settings%2Flhh1%2F%E6%A1%8C%E9%9D%A2%2FCLanguage.htm&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=FFFFFF&color_border=FFFFFF&ad_type=text&ga_vid=583001034.1194442938&ga_sid=1194442938&ga_hid=1942779085&flash=9&u_h=768&u_w=1024&u_ah=740&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency"> #include <iostream.h>
#include <string.h>
#include <stdlib.h>

template <class DataT> class dblinkob {
 public:
   DataT info;
   dblinkob<DataT> *next;
   dblinkob<DataT> *previous;
   dblinkob() {
      info = 0;
      next = NULL;
      previous = NULL;
    }
   dblinkob(DataT c) {
      info = c;
      next = NULL;
      previous = NULL;
    }
   dblinkob<DataT> *getnext() {return next;}
   dblinkob<DataT> *getprevious() {return previous;}
   void getinfo(DataT &c) { c = info;}
   void change(DataT c) {info = c;}
   friend ostream &operator<<(ostream &stream, dblinkob<DataT> o)
    {
      stream << o.info << endl;
      return stream;
    }
   friend ostream &operator<<(ostream &stream, dblinkob<DataT> *o)
    {
      stream << o->info << endl;
      return stream;
    }
   friend istream &operator>>(istream &stream, dblinkob<DataT> &o)
    {
      cout << "Enter information: " << endl;
      stream >> o.info;
      return stream;
    }
 };

template <class DataT> class dllist : public dblinkob<DataT> {
   dblinkob<DataT> *start, *end;
 public:
   dllist() {start = end = NULL;}
   void store(DataT c);
   void remove(dblinkob<DataT> *ob);
   void frwdlist();
   void bkwdlist();
   dblinkob<DataT> *find(DataT c);
   dblinkob<DataT> *getstart() {return start;}
   dblinkob<DataT> *getend() {return end;}
 };

template <class DataT> void dllist<DataT>::store(DataT c)
 {
   dblinkob<DataT> *p;

   p = new dblinkob<DataT>;
   if(!p) {
      cout << "Allocation error." << endl;
      exit(1);
    }
   p->info = c;
   if(start==NULL)
    {
      end = start = p;
    }
   else
    {
      p->previous = end;
      end->next = p;
      end = p;
    }
 }

template <class DataT> void dllist<DataT>::remove(dblinkob<DataT> *ob)
 {
   if(ob->previous)
    {
      ob->previous->next = ob->next;
      if(ob->next)
         ob->next->previous = ob->previous;
      else
         end = ob->previous;
    }
   else
    {
      if(ob->next)
       {
         ob->next->previous = NULL;
         start = ob->next;
       }
      else
         start = end = NULL;
    }
 }

template <class DataT> void dllist<DataT>::frwdlist()
 {
   dblinkob<DataT> *temp;

   temp = start;
   do {
      cout << temp->info << " ";
      temp = temp->getnext();
    } while(temp);
   cout << endl;
 }

template <class DataT> void dllist<DataT>::bkwdlist()
 {
   dblinkob<DataT> *temp;

   temp = end;
   do {
      cout << temp->info << " ";
      temp = temp->getprevious();
   } while(temp);
   cout << endl;
 }

template <class DataT> dblinkob<DataT> *dllist<DataT>::find(DataT c)
 {
   dblinkob<DataT> *temp;

   temp = start;
   while(temp) {
      if(c==temp->info) return temp;
      temp = temp ->getnext();
    }
   return NULL;
 }

int main()
 {
   dllist<char> list;
   char c;
   dblinkob<char> *p;

   list.store('1');
   list.store('2');
   list.store('3');

   cout << "here is list backwards, then forwards." << endl;
   list.bkwdlist();
   list.frwdlist();
   cout << endl;
   cout << "'Manually' walk through the list." << endl;
   p = list.getstart();
   while(p) {
      p->getinfo(c);
      cout << c << " ";
      p = p->getnext();
    }
   cout << endl << endl;
   cout << "Looking for item 2." << endl;
   p = list.find('2');
   if(p)
    {
      p->getinfo(c);
      cout << "Found: " << c << endl;
    }
   cout << endl;
   p->getinfo(c);
   cout << "Removing item: " << c << endl;
   list.remove(p);
   cout << "Here is new list forwards." << endl;
   list.frwdlist();
   cout << endl;
   cout << "Adding an item." << endl;
   list.store('4');
   cout << "Here is list forwards." << endl;
   list.frwdlist();
   cout << endl;
   p = list.find('1');
   if(!p)
    {
      cout << "Error, item not found." << endl;
      return 1;
    }
   p->getinfo(c);
   cout << "Changing " << c << " to 5." << endl;
   p->change('5');
   cout << "Here is list forwards, then backwards." << endl;
   list.frwdlist();
   list.bkwdlist();
   cout << endl;
   cin >> *p;
   cout << p;
   cout << "Here is list forwards again." << endl;
   list.frwdlist();
   cout << endl;
   cout << "Here is list after removing head of list." << endl;
   p = list.getstart();
   list.remove(p);
   list.frwdlist();
   cout << endl;
   cout << "Here is list after removing end of list." << endl;
   p = list.getend();
   list.remove(p);
   list.frwdlist();
   return 0;
 }
 

 

 

 

 

源码编译时报错: [ 0% 22/59233] //external/eigen/blas:libF77blas clang++ xerbla.cpp [ 0% 23/59233] //external/selinux/checkpolicy:checkpolicy lex policy_scan.l [linux_glibc] FAILED: out/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_glibc_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/soong/.intermediates/external/selinux/checkpolicy/checkpolicy/linux_glibc_x86_64/gen/lex/external/selinux/checkpolicy/policy_scan.c external/selinux/checkpolicy/policy_scan.l flex-2.5.39: loadlocale.c:130: _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed. [ 0% 24/59233] test android/soong/third_party/zip [ 0% 25/59233] Target buildinfo: out/target/product/SmartTV256X/obj/ETC/system_build_prop_intermediates/build.prop Target buildinfo from: device/hisilicon/SmartTV256X/system.lowram.prop Target buildinfo from: hikeen/hikeen/order/1006_CS2560P838_RuiDe_PT550GS01_3_U_500mA_DTMB_CMCC/Smart.prop Target FotaUpdateInfo: out/target/product/SmartTV256X/obj/ETC/system_build_prop_intermediates/build.prop [ 0% 26/59233] //external/f2fs-tools:fsck.f2fs clang fsck/quotaio_v2.c [ 0% 27/59233] //frameworks/native/opengl/libs:libEGL_blobCache clang++ EGL/FileBlobCache.cpp [ 0% 28/59233] //frameworks/native/opengl/libs:libEGL_blobCache clang++ EGL/Blob .....省略....... make[4]: Entering directory '/home/zhengzc/A9/AndroidV600R001C00SPC070/out/target/product/SmartTV256X/obj/EMMC_HIBOOT_OBJ/product/driver/common' ln: failed to create symbolic link '../include_inc/hi_osal.h': File exists make[4]: [Makefile:50: prepare] Error 1 (ignored) ln: failed to create symbolic link '../include_inc/osal_ioctl.h': File exists make[4]: [Makefile:51: prepare] Error 1 (ignored) ln: failed to create symbolic link '../include_inc/osal_list.h': File exists make[4]: [Makefile:52: prepare] Error 1 (ignored) ln: failed to create symbolic link 'osal_math.c': File exists make[4]: [M
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值