use_glink.cpp

本文介绍了一个双向链表的数据结构实现及基本操作,包括插入、删除、遍历等,并通过一个具体的C++代码示例展示了如何使用这个双向链表。

  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;
 }
 

 

 

 

 

[thread 0x7fbbe26af8] modem_to_usb_bridge_glink,738 (SUCCESS): poll on '/dev/at_mdm0' returned 1 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,763 (INFO): POLLPRI is set. [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,764 (INFO): Attempting TIOCMGET on '/dev/at_mdm0'... [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,766 (INFO): trying to lock [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,766 (INFO): locked [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,768 (INFO): trying to unlock [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,768 (INFO): unlocked [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,771 (SUCCESS): TIOCMGET on '/dev/at_mdm0' returned 0, signals=0x20 (0x20) [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,776 (INFO): Attempting TIOCMSET on '/dev/at_usb0', signals=0x20 (0x20)... [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,779 (INFO): trying to lock [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,779 (INFO): locked [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,781 (INFO): trying to unlock [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,781 (INFO): unlocked [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,783 (SUCCESS): TIOCMSET on '/dev/at_usb0' returned 0, signals=0x20 (0x20) [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,736 (INFO): Attempting to poll '/dev/at_mdm0'... [E][MOBILE][src/comm/manager_comm_ril.cpp:ReleaseUnsolEventBuf:8462]unsol msg[0x10020002] do NOT release data_buf, memory lost!!!!!!!!!!!!!!!!!!!!!!!!!!!! [E][MOBILE][src/comm/profile_helper.cpp:GetCurrProf:633]zmdkdzCannot get anything. [E][MOBILE][src/comm/manager_comm_ril.cpp:SyncInitialAttachProfileToModem:3608]The profile retriving failed. [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,738 (SUCCESS): poll on '/dev/at_mdm0' returned 1 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,763 (INFO): POLLPRI is set. [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,764 (INFO): Attempting TIOCMGET on '/dev/at_mdm0'... [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,766 (INFO): trying to lock [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,766 (INFO): locked [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,768 (INFO): trying to unlock [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,768 (INFO): unlocked [0x0x5564e050c0] /dev/at_mdm0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,771 (SUCCES[ 68.106751][ T4999] binder: tried to use weak ref as strong ref S): TIOCMGET on '/dev/at_mdm0' returned 0, signals=0xa0 (0x20 | RI) [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,776 (INFO): Attempting TIOCMSET on '/dev/at_usb0', signals=0xa0 (0x20 | RI)... [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,779 (INFO): trying to lock [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,779 (INFO): locked [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,781 (INFO): trying to unlock [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,781 (INFO): unlocked [0x0x5564e05098] /dev/at_usb0 [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,783 (SUCCESS): TIOCMSET on '/dev/at_usb0' returned 0, signals=0xa0 (0x20 | RI) [thread 0x7fbbe26af8] modem_to_usb_bridge_glink,736 (INFO): Attempting to poll '/dev/at_mdm0'... [ 68.228896][ T4999] binder: 4999:4999 transaction failed 29201/-22, size 56-8 line 3199 Si3218x_Init_with_Options(649) size = 1 init_opt = 0 Si3218x: register 0 read = 0x00
09-17
./sys/devices/platform/soc/soc:qcom,smp2p-adsp/wakeup/wakeup45/event_coun ./sys/devices/platform/soc/soc:oplus,vooc/oplus_mms/vooc/wakeup23/event_count ./sys/devices/platform/soc/soc:oplus,vooc/soc:oplus,vooc:oplus,retention_charge/oplus_mms/retention/wakeup28/event_count ./sys/devices/platform/soc/c42d000.qcom,spmi/spmi-0/0-00/c42d000.qcom,spmi:qcom,pmk8550@0:pon_hlos@1300/c42d000.qcom,spmi:qcom,pmk8550@0:pon_hlos@1300:resin/wakeup/wakeup12/event_count ./sys/devices/platform/soc/c42d000.qcom,spmi/spmi-0/0-00/c42d000.qcom,spmi:qcom,pmk8550@0:pon_hlos@1300/c42d000.qcom,spmi:qcom,pmk8550@0:pon_hlos@1300:pwrkey/wakeup/wakeup11/event_count ./sys/devices/platform/soc/c42d000.qcom,spmi/spmi-0/0-00/c42d000.qcom,spmi:qcom,pmk8550@0:rtc@6100/wakeup/wakeup1/event_count ./sys/devices/platform/soc/c42d000.qcom,spmi/spmi-0/0-00/c42d000.qcom,spmi:qcom,pmk8550@0:rtc@6100/rtc/rtc0/alarmtimer.1.auto/wakeup/wakeup2/event_count ./sys/devices/platform/soc/c42d000.qcom,spmi/spmi-0/0-00/c42d000.qcom,spmi:qcom,pmk8550@0:pon_pbs@800/wakeup/wakeup0/event_count ./sys/devices/platform/soc/soc:qcom,pmic_glink/wakeup/wakeup4/event_count ./sys/devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,battery_charger/wakeup/wakeup56/event_count ./sys/devices/platform/soc/soc:qcom,pmic_glink/soc:qcom,pmic_glink:qcom,ucsi/power_supply/ucsi-source-psy-soc:qcom,pmic_glink:qcom,ucsi1/wakeup65/event_count ./sys/devices/platform/soc/soc:qcom,smp2p-modem/wakeup/wakeup46/event_count ./sys/devices/platform/soc/soc:oplus,cpa/oplus_mms/cpa/wakeup25/event_count ./sys/devices/platform/soc/3e00000.qcom,ipa/wakeup/wakeup35/event_count ./sys/devices/platform/soc/88e0000.qcom,msm-eud/wakeup/wakeup7/event_count ./sys/devices/platform/soc/17110040.qcom,wcn6750/wakeup/wakeup26/event_count ./sys/devices/platform/soc/a600000.ssusb/wakeup/wakeup34/event_count ./sys/devices/platform/soc/8c0000.qcom,qupv3_1_geni_se/884000.i2c/i2c-8/8-006f/wakeup/wakeup30/event_count ./sys/devices/platform/soc/8c0000.qcom,qupv3_1_geni_se/884000.i2c/i2c-8/8-006f/ufcs/ufcs/wakeup31/event_coun ./sys/devices/platform/soc/8c0000.qcom,qupv3_1_geni_se/890000.qcom,qup_uart/wakeup/wakeup8/event_count ./sys/devices/platform/soc/soc:qcom,smp2p-cdsp/wakeup/wakeup47/event_count ./sys/devices/platform/soc/soc:oplus,ufcs_charge/oplus_mms/ufcs/wakeup33/event_count ./sys/devices/platform/soc/soc:oplus,comm/oplus_mms/common/wakeup20/event_count ./sys/devices/platform/soc/soc:gpio_key/wakeup/wakeup3/event_count ./sys/devices/platform/soc/soc:spf_core_platform/soc:spf_core_platform:lpass-cdc/va-macro/va_swr_ctrl/wakeup/wakeup55/event_count ./sys/devices/platform/soc/3000000.remoteproc-adsp/wakeup/wakeup14/event_count ./sys/devices/platform/soc/3000000.remoteproc-adsp/remoteproc/remoteproc1/3000000.remoteproc-adsp:glink-edge/3000000.remoteproc-adsp:glink-edge.adsp_apps.-1.-1/wakeup/wakeup53/event_count ./sys/devices/platform/soc/9bb00000.remoteproc-wpss/wakeup/wakeup13/event_count ./sys/devices/platform/soc/4080000.remoteproc-mss/wakeup/wakeup16/event_count ./sys/devices/platform/soc/soc:qcom,pmic_glink_log/wakeup/wakeup5/event_count ./sys/devices/platform/soc/ac0000.qcom,qupv3_0_geni_se/a84000.i2c/i2c-1/1-0028/wakeup/wakeup10/event_count ./sys/devices/platform/soc/ac0000.qcom,qupv3_0_geni_se/a80000.spi/spi_master/spi0/spi0.0/wakeup/wakeup38/event_count ./sys/devices/platform/soc/ac0000.qcom,qupv3_0_geni_se/a80000.spi/spi_master/spi0/spi0.0/wakeup/wakeup39/event_count ./sys/devices/platform/soc/soc:oplus,mms_wired/oplus_mms/wired/wakeup58/event_count ./sys/devices/platform/soc/soc:oplus,mms_wired/oplus_mms/wired/usb/wakeup59/event_count ./sys/devices/platform/soc/soc:oplus,monitor/oplus_mms/error/wakeup32/event_count ./sys/devices/platform/soc/soc:oplus,mms_gauge/oplus_mms/gauge/battery/wakeup60/event_count ./sys/devices/platform/soc/soc:oplus,mms_gauge/oplus_mms/gauge/wakeup57/event_count ./sys/devices/platform/soc/soc:oplus,plc_charge/oplus_mms/plc/wakeup21/event_count ./sys/devices/platform/soc/32300000.remoteproc-cdsp/wakeup/wakeup15/event_count ./sys/devices/platform/soc/soc:qcom,smp2p_sleepstate/wakeup/wakeup9/event_count ./sys/devices/platform/soc/soc:oplus,pps_charge/oplus_mms/pps/wakeup27/event_count ./sys/devices/virtual/wakeup/wakeup86/event_count ./sys/devices/virtual/wakeup/wakeup118/event_count ./sys/devices/virtual/wakeup/wakeup48/event_count ./sys/devices/virtual/wakeup/wakeup76/event_count ./sys/devices/virtual/wakeup/wakeup108/event_count ./sys/devices/virtual/wakeup/wakeup66/event_count ./sys/devices/virtual/wakeup/wakeup94/event_count ./sys/devices/virtual/wakeup/wakeup126/event_count ./sys/devices/virtual/wakeup/wakeup84/event_count ./sys/devices/virtual/wakeup/wakeup116/event_count ./sys/devices/virtual/wakeup/wakeup74/event_count ./sys/devices/virtual/wakeup/wakeup106/event_count ./sys/devices/virtual/wakeup/wakeup36/event_count ./sys/devices/virtual/wakeup/wakeup64/event_count ./sys/devices/virtual/wakeup/wakeup92/event_count ./sys/devices/virtual/wakeup/wakeup124/event_count ./sys/devices/virtual/wakeup/wakeup54/event_count ./sys/devices/virtual/wakeup/wakeup82/event_count ./sys/devices/virtual/wakeup/wakeup114/event_count ./sys/devices/virtual/wakeup/wakeup44/event_count ./sys/devices/virtual/wakeup/wakeup72/event_count ./sys/devices/virtual/wakeup/wakeup104/event_count ./sys/devices/virtual/wakeup/wakeup62/event_count ./sys/devices/virtual/wakeup/wakeup90/event_count ./sys/devices/virtual/wakeup/wakeup24/event_count ./sys/devices/virtual/wakeup/wakeup122/event_count ./sys/devices/virtual/wakeup/wakeup52/event_count ./sys/devices/virtual/wakeup/wakeup80/event_count ./sys/devices/virtual/wakeup/wakeup112/event_count ./sys/devices/virtual/wakeup/wakeup42/event_count ./sys/devices/virtual/wakeup/wakeup70/event_count ./sys/devices/virtual/wakeup/wakeup102/event_count ./sys/devices/virtual/wakeup/wakeup99/event_count ./sys/devices/virtual/wakeup/wakeup89/event_count ./sys/devices/virtual/wakeup/wakeup22/event_count ./sys/devices/virtual/wakeup/wakeup120/event_count ./sys/devices/virtual/wakeup/wakeup50/event_count ./sys/devices/virtual/wakeup/wakeup79/event_count ./sys/devices/virtual/wakeup/wakeup110/event_count ./sys/devices/virtual/wakeup/wakeup40/event_count ./sys/devices/virtual/wakeup/wakeup69/event_count ./sys/devices/virtual/wakeup/wakeup100/event_count ./sys/devices/virtual/wakeup/wakeup97/event_count ./sys/devices/virtual/wakeup/wakeup87/event_count ./sys/devices/virtual/wakeup/wakeup119/event_count ./sys/devices/virtual/wakeup/wakeup49/event_count ./sys/devices/virtual/wakeup/wakeup77/event_count ./sys/devices/virtual/wakeup/wakeup109/event_count ./sys/devices/virtual/wakeup/wakeup67/event_count ./sys/devices/virtual/wakeup/wakeup95/event_count ./sys/devices/virtual/wakeup/wakeup29/event_count ./sys/devices/virtual/wakeup/wakeup127/event_count ./sys/devices/virtual/wakeup/wakeup85/event_count ./sys/devices/virtual/wakeup/wakeup19/event_count ./sys/devices/virtual/wakeup/wakeup117/event_count ./sys/devices/virtual/wakeup/wakeup75/event_count ./sys/devices/virtual/wakeup/wakeup107/event_count ./sys/devices/virtual/wakeup/wakeup37/event_count ./sys/devices/virtual/wakeup/wakeup93/event_count ./sys/devices/virtual/wakeup/wakeup125/event_count ./sys/devices/virtual/wakeup/wakeup83/event_count ./sys/devices/virtual/wakeup/wakeup115/event_count ./sys/devices/virtual/wakeup/wakeup73/event_count ./sys/devices/virtual/wakeup/wakeup105/event_count ./sys/devices/virtual/wakeup/wakeup63/event_count ./sys/devices/virtual/wakeup/wakeup91/event_count ./sys/devices/virtual/wakeup/wakeup123/event_count ./sys/devices/virtual/wakeup/wakeup81/event_count ./sys/devices/virtual/wakeup/wakeup113/event_count ./sys/devices/virtual/wakeup/wakeup43/event_count ./sys/devices/virtual/wakeup/wakeup71/event_count ./sys/devices/virtual/wakeup/wakeup103/event_count ./sys/devices/virtual/wakeup/wakeup61/event_count ./sys/devices/virtual/wakeup/wakeup121/event_count ./sys/devices/virtual/wakeup/wakeup51/event_count ./sys/devices/virtual/wakeup/wakeup111/event_count ./sys/devices/virtual/wakeup/wakeup41/event_count ./sys/devices/virtual/wakeup/wakeup101/event_count ./sys/devices/virtual/wakeup/wakeup98/event_count ./sys/devices/virtual/wakeup/wakeup88/event_count ./sys/devices/virtual/wakeup/wakeup6/event_count ./sys/devices/virtual/wakeup/wakeup78/event_count ./sys/devices/virtual/wakeup/wakeup68/event_count ./sys/devices/virtual/wakeup/wakeup96/event_count ./sys/devices/virtual/fastrpc/adsprpc-smd/wakeup17/event_count ./sys/devices/virtual/fastrpc/adsprpc-smd-secure/wakeup18/event_count 用尽可能少的正则表达式来表示上面的路径,且要符合 `sepolicy` 相关规则
最新发布
10-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值